<jupyter_start><jupyter_text>Summary  scikit-learn API ``X`` : data, 2d numpy array or scipy sparse matrix of shape (n_samples, n_features)``y`` : targets, 1d numpy array of shape (n_samples,) ``model.fit(X_train, [y_train])````model.predict(X_test)````model.transform(X_test)``ClassificationPreprocessingRegressionDimensionality ReductionClusteringFeature Extraction&nbsp;Feature selection  Model evaluation and parameter selection<jupyter_code>from sklearn.datasets import load_digits
from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import cross_val_score

digits = load_digits()
X, y = digits.data / 16., digits.target

cross_val_score(LogisticRegression(), X, y, cv=5)
from sklearn.grid_search import GridSearchCV
from sklearn.cross_validation import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y)
grid = GridSearchCV(LogisticRegression(), param_grid={'C': np.logspace(-3, 2, 6)})
grid.fit(X_train, y_train)
grid.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>Model complexity, overfitting, underfitting ![underfitting and overfitting](overfitting_underfitting_cartoon.svg)  Pipelines<jupyter_code>from sklearn.pipeline import make_pipeline
from sklearn.feature_selection import SelectKBest
pipe = make_pipeline(SelectKBest(k=59), LogisticRegression())
pipe.fit(X_train, y_train)
pipe.score(X_test, y_test)<jupyter_output>C:\Users\andy\Anaconda\lib\site-packages\sklearn\feature_selection\univariate_selection.py:111: UserWarning: Features [ 0 32 39 56] are constant.
  UserWarning)
C:\Users\andy\Anaconda\lib\site-packages\sklearn\feature_selection\univariate_selection.py:112: RuntimeWarning: invalid value encountered in divide
  f = msb / msw<jupyter_text>Scoring metrics<jupyter_code>cross_val_score(LogisticRegression(C=.01), X, y == 3, cv=5)
cross_val_score(LogisticRegression(C=.01), X, y == 3, cv=5, scoring="roc_auc")<jupyter_output><empty_output><jupyter_text>Data Wrangling<jupyter_code>from sklearn.preprocessing import OneHotEncoder

X = np.array([[15.9, 1], # from Tokyo
              [21.5, 2], # from New York
              [31.3, 0], # from Paris
              [25.1, 2], # from New York
              [63.6, 1], # from Tokyo
              [14.4, 1], # from Tokyo
              ])

y = np.array([0, 1, 1, 1, 0, 0])

encoder = OneHotEncoder(categorical_features=[1], sparse=False)
pipe = make_pipeline(encoder, LogisticRegression())
pipe.fit(X, y)
pipe.score(X, y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11939102564102565, 'fraction_numerical': 0.024839743589743588, 'mean_word_length': 6.014044943820225, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '28558', 'license': 'Apache-2.0', 'n_tokens_mistral': 906, 'n_tokens_neox': 844, 'n_words': 178, 'path': 'scikit/Chapter 9/Summary.ipynb', 'repo_name': 'KarthikKothareddy/Data-Science-Practice', 'size': '2496'}