Difference between revisions of "Sklearn"
Jump to navigation
Jump to search
| Line 60: | Line 60: | ||
|} | |} | ||
| − | === | + | ===A Simple Python Model Implementation=== |
<syntaxhighlight lang=python>#import data | <syntaxhighlight lang=python>#import data | ||
all_data = pd.read_csv('my_data_file.csv') | all_data = pd.read_csv('my_data_file.csv') | ||
| Line 76: | Line 76: | ||
print(mean_absolute_error(y_test, y_pred)) | print(mean_absolute_error(y_test, y_pred)) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | ===Kaggle's 7 Steps of Machine Learning=== | ||
| + | # Gather the data | ||
| + | # Prepare the data | ||
| + | # Select a model | ||
| + | # Train the model | ||
| + | # Evaluate the model | ||
| + | # Tune parameters | ||
| + | # Make predictions | ||
Revision as of 20:37, 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))
Kaggle's 7 Steps of Machine Learning
- Gather the data
- Prepare the data
- Select a model
- Train the model
- Evaluate the model
- Tune parameters
- Make predictions