78 lines
4.1 KiB
Plaintext
78 lines
4.1 KiB
Plaintext
Traceback (most recent call last):
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/jupyter_cache/executors/utils.py", line 51, in single_nb_execution
|
|
executenb(
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/client.py", line 1204, in execute
|
|
return NotebookClient(nb=nb, resources=resources, km=km, **kwargs).execute()
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/util.py", line 84, in wrapped
|
|
return just_run(coro(*args, **kwargs))
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/util.py", line 62, in just_run
|
|
return loop.run_until_complete(coro)
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
|
|
return future.result()
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/client.py", line 663, in async_execute
|
|
await self.async_execute_cell(
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/client.py", line 965, in async_execute_cell
|
|
await self._check_raise_for_error(cell, cell_index, exec_reply)
|
|
File "/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/nbclient/client.py", line 862, 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)
|
|
Input [0;32mIn [8][0m, in [0;36m<cell line: 36>[0;34m()[0m
|
|
[1;32m 32[0m [38;5;28mprint[39m(accuracy)
|
|
[1;32m 33[0m [38;5;28mprint[39m([38;5;124m"[39m[38;5;124mTest set accuracy with Logistic Regression and scaled data: [39m[38;5;132;01m{:.2f}[39;00m[38;5;124m"[39m[38;5;241m.[39mformat(logreg[38;5;241m.[39mscore(X_test_scaled,y_test)))
|
|
[0;32m---> 36[0m [38;5;28;01mimport[39;00m [38;5;21;01mscikitplot[39;00m [38;5;28;01mas[39;00m [38;5;21;01mskplt[39;00m
|
|
[1;32m 37[0m y_pred [38;5;241m=[39m logreg[38;5;241m.[39mpredict(X_test_scaled)
|
|
[1;32m 38[0m skplt[38;5;241m.[39mmetrics[38;5;241m.[39mplot_confusion_matrix(y_test, y_pred, normalize[38;5;241m=[39m[38;5;28;01mTrue[39;00m)
|
|
|
|
[0;31mModuleNotFoundError[0m: No module named 'scikitplot'
|
|
ModuleNotFoundError: No module named 'scikitplot'
|
|
|