This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_blind = blind[['Depth', 'GR', 'ILD_log10','DeltaPHI', 'PHIND', 'PE', 'NM_M', 'RELPOS', 'Formation_num']] | |
y_blind = blind['Facies'] | |
# scale | |
scaler = StandardScaler() | |
X_blind = scaler.fit_transform(X_blind) | |
# define Classifiers | |
log = LogisticRegression(C = 10, solver = 'lbfgs', max_iter= 300 ) | |
knn = KNeighborsClassifier(leaf_size = 10, n_neighbors=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
from sklearn import svm, datasets | |
from sklearn.metrics import roc_curve, auc | |
from sklearn.preprocessing import label_binarize | |
from sklearn.multiclass import OneVsRestClassifier | |
from scipy import interp | |
from sklearn.metrics import roc_auc_score | |
# Binarize the output | |
yy = label_binarize(y_sm, classes=[ 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
from sklearn import svm, datasets | |
from sklearn.metrics import roc_curve, auc | |
from sklearn.preprocessing import label_binarize | |
from sklearn.multiclass import OneVsRestClassifier | |
from scipy import interp | |
from sklearn.metrics import roc_auc_score | |
from sklearn.model_selection import learning_curve | |
from sklearn.model_selection import ShuffleSplit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import confusion_matrix | |
import itertools | |
# define function to implement confusion matrix with normalization capability | |
def plot_confusion_matrix(cm, classes, normalize=False, | |
title='Confusion matrix', | |
cmap=plt.cm.Reds): | |
if normalize: | |
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import classification_report | |
from sklearn.model_selection import KFold | |
from sklearn.model_selection import cross_validate | |
from sklearn.metrics import precision_recall_fscore_support | |
# define Classifiers with optimum hyper_param | |
log = LogisticRegression(C = 10, solver = 'lbfgs', max_iter= 200 ) | |
knn = KNeighborsClassifier(leaf_size = 10, n_neighbors=2) | |
dtree = DecisionTreeClassifier(criterion = 'entropy', max_depth=15) | |
rtree = RandomForestClassifier(criterion='entropy', max_depth=20, n_estimators=300) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import GridSearchCV | |
X_train, X_test, y_train, y_test = train_test_split(X_sm, y_sm, test_size=0.2, random_state=42) | |
#----------------------------------------------------------------logistic regression classifier | |
#define hyper parameters and ranges | |
param_grid_log = [{'C': [0.1, 1, 10], 'solver': ['lbfgs', 'liblinear'], | |
'max_iter':[100, 300]}] | |
#apply gridsearch | |
grid_log = GridSearchCV(log, param_grid=param_grid_log, cv=5) | |
#fit model with grid search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LogisticRegression | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.svm import SVC | |
from sklearn.naive_bayes import GaussianNB | |
from sklearn.ensemble import GradientBoostingClassifier | |
from sklearn.ensemble import ExtraTreesClassifier | |
# define Classifiers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.inspection import permutation_importance | |
model = LogisticRegression(solver='liblinear') | |
# fit the model | |
model.fit(X, y) | |
# perform permutation importance | |
results = permutation_importance(model, X, y, scoring='accuracy') | |
# get importance | |
importance = results.importances_mean | |
# summarize feature importance | |
for i,v in enumerate(importance): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.tree import DecisionTreeClassifier | |
model = DecisionTreeClassifier() | |
# fit the model | |
model.fit(X, y) | |
# get importance | |
importance = model.feature_importances_ | |
# summarize feature importance | |
for i,v in enumerate(importance): | |
print('Feature: %0d, Score: %.5f' % (i,v)) | |
# plot feature importance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# logistic regression for feature importance | |
from sklearn.datasets import make_classification | |
from sklearn.linear_model import LinearRegression | |
from matplotlib import pyplot | |
# define dataset | |
model = LinearRegression() | |
# fit the model | |
model.fit(X, y) | |
# get importance | |
importance = model.coef_ |
NewerOlder