<jupyter_start><jupyter_text>Check if columns has null values<jupyter_code>data.isna().sum()<jupyter_output><empty_output><jupyter_text>Remove every line that has null values within these columns<jupyter_code>columns = ['price',
           'points',
           'variety',
           'taster_name',
           'country',
           'winery'
          ]

for col in columns:
    data = data[pd.notnull(data[col])]
data.isna().sum()<jupyter_output><empty_output><jupyter_text>First classifier, predict taster name As a first classifier, we are going to use only the points and the prices, which are numeric data, to predict who is the Taster.<jupyter_code>X = data[['points', 'price']]
X.head()
y = data['taster_name']
y.head()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 42)
print('Training Features Shape:', X_train.shape)
print('Training Labels Shape:', y_train.shape)
print('Testing Features Shape:', X_test.shape)
print('Testing Labels Shape:', y_test.shape)<jupyter_output>Training Features Shape: (72315, 2)
Training Labels Shape: (72315,)
Testing Features Shape: (24105, 2)
Testing Labels Shape: (24105,)<jupyter_text>Here we create our RandomForestClassifier<jupyter_code>clf = LogisticRegression()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
y_pred
accuracy_score(y_test, y_pred)
clf.coef_.tolist()<jupyter_output><empty_output><jupyter_text>Second classifier, predict taster name with more columns For the second classifier, we are going to use categorical data, the country and the variety of wine.<jupyter_code>X = data[['points', 'price', 'country', 'variety']]
X.head()<jupyter_output><empty_output><jupyter_text>We cannot make use of the categorical data as is within our model, we need it to be in a OneHot format. Pandas provide a function called get_dummies that does just that.<jupyter_code>X = pd.get_dummies(data=X, columns=['variety', 'country'])
y = data.taster_name
X.shape, y.shape
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 42)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
accuracy_score(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Using GridSearch to find the best hyperparameters Here we'd like to find the best hyperparameters of our RandomForestClassifier using GridSearchCV. Specify here which parameter you want to Cross Validate and try to get a better model.<jupyter_code>random_forest_classifier = RandomForestClassifier(n_estimators=10,
                                                  n_jobs=5,
                                                  oob_score=False)
def report(results, n_top=3):
    for i in range(1, n_top + 1):
        candidates = np.flatnonzero(results['rank_test_score'] == i)
        for candidate in candidates:
            print("Model with rank: {0}".format(i))
            print("Mean validation score: {0:.3f} (std: {1:.3f})".format(
                  results['mean_test_score'][candidate],
                  results['std_test_score'][candidate]))
            print("Parameters: {0}".format(results['params'][candidate]))
            print("")
param_dist = {"n_estimators": range(2, 50, 2),
              "n_jobs": range(1, 20, 3)}
random_forest_classifier = RandomForestClassifier(bootstrap= True, 
                                                  criterion='gini', 
                                                  max_depth=None, 
                                                  max_features= 31, 
                                                  min_samples_split=24)
n_iter_search = 20
random_search = RandomizedSearchCV(random_forest_classifier,
                                   param_distributions=param_dist,
                                   n_iter=n_iter_search,
                                   cv=5)
start = time()
random_search.fit(X_train, y_train)
print("RandomizedSearchCV took %.2f seconds for %d candidates"
      " parameter settings." % ((time() - start), n_iter_search))
report(random_search.cv_results_)<jupyter_output><empty_output><jupyter_text>Third classifier, predict price with points<jupyter_code>X = data[['points']]
X.head()
y = data[['price']]
y.head()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 42)
print('Training Features Shape:', X_train.shape)
print('Training Labels Shape:', y_train.shape)
print('Testing Features Shape:', X_test.shape)
print('Testing Labels Shape:', y_test.shape)
linear_regression = LinearRegression()
X_test.points
linear_regression.fit(X_train, y_train)
linear_regression.score(X_test, y_test)
linear_regression.predict(X_test)
# plot prediction and actual data
y_pred = linear_regression.predict(X_test) 
plt.plot(y_test, y_pred, '.')

# plot a line, a perfit predict would all fall on this line
x = np.linspace(0, 100, 50)
y = x
plt.plot(x, y)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11095218635063343, 'fraction_numerical': 0.014507560277891296, 'mean_word_length': 3.4867094408799266, 'pattern_counts': {'":': 2, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '588506', 'license': 'CC0-1.0', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1533, 'n_words': 388, 'path': 'notebooks/Tutoriel 3 - Wine.ipynb', 'repo_name': 'ngarneau/accuracySharedTask', 'size': '4894'}