Challenge Solution Review

In this lesson, we explain the solution to the last challenge lesson.

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
import sklearn.preprocessing as preprocessing
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_classif
from sklearn.linear_model import LogisticRegression
import sklearn.metrics as metrics
df = pd.read_csv("./challenge1.csv", sep=",", header=0)
y = df.pop("target").values
X = df
minmax = preprocessing.MinMaxScaler()
X_minmax = minmax.transform(X)
sb = SelectKBest(f_classif, 10), y)
X_stage2 = sb.transform(X_minmax)
train_x, test_x, train_y, test_y = train_test_split(X_stage2,
lr = LogisticRegression(), train_y)
pred_y = lr.predict(test_x)
f1 = metrics.f1_score(test_y, pred_y)
print("The F1-score is {}.".format(f1))

Get hands-on with 1200+ tech skills courses.