Sklearn
Revision as of 20:38, 24 February 2021 by User (talk | contribs) (→Kaggle's 7 Steps of Machine Learning)
Overview
Summary of Syntax
| Module | Methods | Module | Methods |
|---|---|---|---|
| sklearn.metrics | precision_score, recall_score, f1_score, confusion_matrix, precision_recall_curve, mean_squared_error, accuracy_score, silhouette_score, silhouette_samples |
sklearn.impute | SimpleImputer |
| sklearn.model_selection | cross_val_predict, cross_val_score, StratifiedKFold, train_test_split, StratifiedShuffleSplit, GridSearchCV, RandomizedSearchCV, ShuffleSplit |
sklearn.preprocessing | OrdinalEncoder, OneHotEncoder, StandardScaler, PolynomialFeatures, MinMaxScaler |
| sklearn.linear_model | SGDClassifier, LinearRegression, Ridge, Lasso, LogisticRegression, Perceptron |
sklearn.pipeline | Pipeline |
| sklearn.tree | DecisionTreeRegressor, DecisionTreeClassifier, |
sklearn.compose | ColumnTransformer |
| sklearn.ensemble | RandomForestRegressor, RandomForestClassifier, VotingClassifier, Bagging Classifier, AdaBoostClassifier, GradientBoostingRegressor, ExtraTreesClassifier, |
sklearn.svm | SVR, SVC, LinearSVC, LinearSVR |
| sklearn.base | clone, BaseEstimator, TransformerMixin |
sklearn.multiclass | OneVsRestClassifier, |
| sklearn.neighbors | KNeighborsClassifier, | sklearn.neural_network | MLPClassifier, |
| sklearn.decomposition | PCA, IncrementalPCA, KernelPCA, |
sklearn.manifold | LocallyLinearEmbedding, MDS, Isomap, TSNE, |
| sklearn.discriminant_analysis | LinearDiscriminantAnalysis, |
sklearn.mixture | GaussianMixture, BayesianGaussianMixture |
| sklearn.cluster | KMeans, MiniBatchKMeans, DBSCAN, SpectralClustering, AgglomerativeClustering |
A Simple Python Model Implementation
#import data
all_data = pd.read_csv('my_data_file.csv')
# drop nan rows (for both train & test)
data = all_data.dropna(axis=0)
# Split data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
# instantiate the model
model = MySpecialRegressor()
# Fit the model to the training data
model.fit(X_train, y_train)
# Use trained model to predict y_test values from X_test values
y_pred = model.predict(X_test)
# Check results
print(mean_absolute_error(y_test, y_pred))
7 Steps of Machine Learning (from Kaggle)
- Gather the data
- Prepare the data
- Select a model
- Train the model
- Evaluate the model
- Tune parameters
- Make predictions