Difference between revisions of "Sklearn"

From Bitnami MediaWiki
Jump to navigation Jump to search
(Created page with "===Overview=== ===Summary of Syntax=== {| class="wikitable" |- ! Module ! Methods ! Module ! Methods |- | sklearn.metrics | precision_score, <br />recall_score, <br />f1_sco...")
 
Line 59: Line 59:
 
|  
 
|  
 
|}
 
|}
 +
 +
===Basics of Model Building===
 +
<syntaxhighlight lang=python>all_data = pd.read_csv('my_data_file.csv')
 +
data = all_data.dropna(axis=0)  # drop nan rows
 +
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
 +
model = MySpecialRegressor() # instantiate the model
 +
model.fit(X_train, y_train)  # Fit the model to the training data
 +
y_pred = model.predict(X_test)  # Use model to predict y_test values
 +
print(mean_absolute_error(y_test, y_pred))
 +
</syntaxhighlight>

Revision as of 17:34, 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

Basics of Model Building

all_data = pd.read_csv('my_data_file.csv')
data = all_data.dropna(axis=0)  # drop nan rows
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
model = MySpecialRegressor() # instantiate the model
model.fit(X_train, y_train)  # Fit the model to the training data
y_pred = model.predict(X_test)  # Use model to predict y_test values
print(mean_absolute_error(y_test, y_pred))