<jupyter_start><jupyter_text>Pumpkin Varieties and ColorLoad up required libraries and dataset. Convert the data to a dataframe containing a subset of the data: Let's look at the relationship between color and variety<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
pumpkins = pd.read_csv('US-pumpkins.csv')

pumpkins.head()

from sklearn.preprocessing import LabelEncoder

new_columns = ["Color", "Origin", "Item Size", "Variety", "City Name", "Package"]

new_pumpkins = pumpkins.drop([c for c in pumpkins.columns if c not in new_columns], axis = 1)
new_pumpkins.dropna(inplace = True)
new_pumpkins = new_pumpkins.apply(LabelEncoder().fit_transform)
new_pumpkins["Price"] = (pumpkins["Low Price"] + pumpkins["High Price"])/2
new_pumpkins.info()
_ = sns.catplot(x="Color", y="Price", kind = "violin", data=new_pumpkins)
sns.catplot(x="Color", y="Item Size", kind = "violin", data=new_pumpkins)
_ = sns.catplot(x="Color", y="Variety", kind = "violin", data=new_pumpkins)
_ = sns.catplot(x="Color", y="Package", kind = "violin", data=new_pumpkins)
_ = sns.catplot(x="Color", y="City Name", kind = "violin", data=new_pumpkins)
_ = sns.catplot(x="Color", y="Origin", kind = "violin", data=new_pumpkins)<jupyter_output><empty_output><jupyter_text>Distributions of Price, Package and Variety look different for each color so, we  could use this features trying to make predictions of the colors of pumpkins<jupyter_code>_ = new_pumpkins["Color"].value_counts().plot(kind="bar")<jupyter_output><empty_output><jupyter_text>We observe that data is imbalaced so we would try to mitigate it interpolating features<jupyter_code>features = ["Price", "Package"]
X = new_pumpkins.drop([c for c in new_pumpkins.columns if c not in features], axis=1)
y = new_pumpkins[["Color"]]<jupyter_output><empty_output><jupyter_text>Now we select the color feature as target and the others as predictor<jupyter_code>from imblearn.over_sampling import  SMOTE
smote = SMOTE(k_neighbors=6)
X_, y_ = smote.fit_resample(X,y)
pd.Series(y_).value_counts().plot(kind = "bar")<jupyter_output><empty_output><jupyter_text>Now we have balanced categories let proceed to train the model<jupyter_code>from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X_,y_, train_size = 0.2, random_state = 0)
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report

model = LogisticRegression()
model.fit(X_train, y_train)
pred = model.predict(X_test)

print(classification_report(y_test, pred))
print(f"model acc: {accuracy_score(y_test.ravel(), pred)}")
print(f"predictions: {pred}")
from sklearn.metrics import  roc_curve, roc_auc_score

y_scores = model.predict_proba(X_test)

fpr, tpr, tresholds = roc_curve(y_test, y_scores[:,1])
print(f"auc_score:{roc_auc_score(y_test, y_scores[:,1])}")
sns.lineplot(x=[0,1],y=[0,1])
_ = sns.lineplot(x=fpr, y=tpr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1285329744279946, 'fraction_numerical': 0.004374158815612382, 'mean_word_length': 7.667638483965015, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '29124', 'license': 'MIT', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1059, 'n_words': 252, 'path': '2-Regression/4-Logistic/notebook.ipynb', 'repo_name': 'jtracos/ML-For-Beginners', 'size': '2972'}