78 lines
3.9 KiB
Plaintext
78 lines
3.9 KiB
Plaintext
Traceback (most recent call last):
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/jupyter_cache/executors/utils.py", line 51, in single_nb_execution
|
|
executenb(
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/client.py", line 1087, in execute
|
|
return NotebookClient(nb=nb, resources=resources, km=km, **kwargs).execute()
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/util.py", line 74, in wrapped
|
|
return just_run(coro(*args, **kwargs))
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/util.py", line 53, in just_run
|
|
return loop.run_until_complete(coro)
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
|
|
return future.result()
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/client.py", line 540, in async_execute
|
|
await self.async_execute_cell(
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/client.py", line 832, in async_execute_cell
|
|
self._check_raise_for_error(cell, exec_reply)
|
|
File "/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/nbclient/client.py", line 740, in _check_raise_for_error
|
|
raise CellExecutionError.from_cell_and_msg(cell, exec_reply['content'])
|
|
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
|
|
------------------
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from sklearn.model_selection import train_test_split
|
|
from sklearn.datasets import load_breast_cancer
|
|
from sklearn.linear_model import LogisticRegression
|
|
|
|
# Load the data
|
|
cancer = load_breast_cancer()
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
|
|
print(X_train.shape)
|
|
print(X_test.shape)
|
|
# Logistic Regression
|
|
logreg = LogisticRegression(solver='lbfgs')
|
|
logreg.fit(X_train, y_train)
|
|
print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
|
|
#now scale the data
|
|
from sklearn.preprocessing import StandardScaler
|
|
scaler = StandardScaler()
|
|
scaler.fit(X_train)
|
|
X_train_scaled = scaler.transform(X_train)
|
|
X_test_scaled = scaler.transform(X_test)
|
|
# Logistic Regression
|
|
logreg.fit(X_train_scaled, y_train)
|
|
print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
|
|
|
|
|
|
from sklearn.preprocessing import LabelEncoder
|
|
from sklearn.model_selection import cross_validate
|
|
#Cross validation
|
|
accuracy = cross_validate(logreg,X_test_scaled,y_test,cv=10)['test_score']
|
|
print(accuracy)
|
|
print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
|
|
|
|
|
|
import scikitplot as skplt
|
|
y_pred = logreg.predict(X_test_scaled)
|
|
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
|
|
plt.show()
|
|
y_probas = logreg.predict_proba(X_test_scaled)
|
|
skplt.metrics.plot_roc(y_test, y_probas)
|
|
plt.show()
|
|
skplt.metrics.plot_cumulative_gain(y_test, y_probas)
|
|
plt.show()
|
|
------------------
|
|
|
|
[0;31m---------------------------------------------------------------------------[0m
|
|
[0;31mModuleNotFoundError[0m Traceback (most recent call last)
|
|
[0;32m<ipython-input-8-12adb44b1c20>[0m in [0;36m<module>[0;34m[0m
|
|
[1;32m 34[0m [0;34m[0m[0m
|
|
[1;32m 35[0m [0;34m[0m[0m
|
|
[0;32m---> 36[0;31m [0;32mimport[0m [0mscikitplot[0m [0;32mas[0m [0mskplt[0m[0;34m[0m[0;34m[0m[0m
|
|
[0m[1;32m 37[0m [0my_pred[0m [0;34m=[0m [0mlogreg[0m[0;34m.[0m[0mpredict[0m[0;34m([0m[0mX_test_scaled[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
|
[1;32m 38[0m [0mskplt[0m[0;34m.[0m[0mmetrics[0m[0;34m.[0m[0mplot_confusion_matrix[0m[0;34m([0m[0my_test[0m[0;34m,[0m [0my_pred[0m[0;34m,[0m [0mnormalize[0m[0;34m=[0m[0;32mTrue[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
|
|
|
[0;31mModuleNotFoundError[0m: No module named 'scikitplot'
|
|
ModuleNotFoundError: No module named 'scikitplot'
|
|
|