This file contains hidden or 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
plt.figure() | |
joyplot( | |
data=sydney[['MaxTemp', 'Month']], | |
by='Month', | |
figsize=(12, 8) | |
) | |
plt.title('Ridgeline Plot of Max Temperatures in Sydney', fontsize=20) | |
plt.show() |
This file contains hidden or 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 pandas.api.types import CategoricalDtype | |
cat_month = CategoricalDtype( | |
['January', 'February', 'March', 'April', 'May', 'June', | |
'July', 'August', 'September', 'October', 'November', 'December'] | |
) | |
sydney['Month'] = sydney['Month'].astype(cat_month) | |
sydney.dtypes |
This file contains hidden or 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
sydney = df.query("Location == 'Sydney'") | |
sydney = sydney.drop('Location', axis=1) | |
sydney['Date'] = sydney['Date'].astype('datetime64') | |
sydney['Month'] = sydney['Date'].dt.month_name() | |
sydney.head() |
This file contains hidden or 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
import pandas as pd | |
import matplotlib.pyplot as plt | |
from joypy import joyplot | |
df = pd.read_csv('weatherAUS.csv', usecols=['Date', 'Location', 'MinTemp', 'MaxTemp']) | |
df.head() |
This file contains hidden or 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
exp = explainer.explain_instance( | |
data_row=X_test.iloc[4], | |
predict_fn=model.predict_proba | |
) | |
exp.show_in_notebook(show_table=True) |
This file contains hidden or 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
exp = explainer.explain_instance( | |
data_row=X_test.iloc[1], | |
predict_fn=model.predict_proba | |
) | |
exp.show_in_notebook(show_table=True) |
This file contains hidden or 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
import lime | |
from lime import lime_tabular | |
explainer = lime_tabular.LimeTabularExplainer( | |
training_data=np.array(X_train), | |
feature_names=X_train.columns, | |
class_names=['bad', 'good'], | |
mode='classification' | |
) |
This file contains hidden or 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.ensemble import RandomForestClassifier | |
model = RandomForestClassifier(random_state=42) | |
model.fit(X_train, y_train) | |
score = model.score(X_test, y_test) |
This file contains hidden or 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 train_test_split | |
X = wine.drop('quality', axis=1) | |
y = wine['quality'] | |
X_train, X_test, y_train, y_test = train_test_split( | |
X, y, test_size=0.2, random_state=42 | |
) |
This file contains hidden or 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
import numpy as np | |
import pandas as pd | |
wine = pd.read_csv('wine.csv') | |
wine.head() |