Difference between revisions of "Sklearn"

From Bitnami MediaWiki
Jump to navigation Jump to search
Line 77: Line 77:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
−
===Kaggle's 7 Steps of Machine Learning===
+
===7 Steps of Machine Learning (from [https://www.kaggle.com/alexisbcook/intro-to-automl Kaggle])===
 
# Gather the data
 
# Gather the data
 
# Prepare the data
 
# Prepare the data

Revision as of 20:38, 24 February 2021

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)

  1. Gather the data
  2. Prepare the data
  3. Select a model
  4. Train the model
  5. Evaluate the model
  6. Tune parameters
  7. Make predictions