Challenge Solution Review
In this lesson, we explain the solution to the last challenge lesson.
We'll cover the following...
We'll cover the following...
Python 3.5
import pandas as pdimport numpy as npfrom sklearn.model_selection import train_test_splitimport sklearn.preprocessing as preprocessingfrom sklearn.feature_selection import SelectKBestfrom sklearn.feature_selection import f_classiffrom sklearn.linear_model import LogisticRegressionimport sklearn.metrics as metricsdf = pd.read_csv("./challenge1.csv", sep=",", header=0)y = df.pop("target").valuesX = dfminmax = preprocessing.MinMaxScaler()minmax.fit(X)X_minmax = minmax.transform(X)sb = SelectKBest(f_classif, 10)sb.fit(X_minmax, y)X_stage2 = sb.transform(X_minmax)train_x, test_x, train_y, test_y = train_test_split(X_stage2,y,test_size=0.2,random_state=42)lr = LogisticRegression()lr.fit(train_x, train_y)pred_y = lr.predict(test_x)f1 = metrics.f1_score(test_y, pred_y)print("The F1-score is {}.".format(f1))
First, you need to load the dataset from challenge1.csv
by read_csv
. Here we use the pandas
library, which is a widely used library for data processing. If you are not familiar with this library, you can check the course ...