Search⌘ K
AI Features

Challenge Solution Review

Explore how to handle nonlinear datasets by loading and splitting data with pandas, then apply support vector machines using an RBF kernel. Learn to train the model and evaluate its performance using the F1-score metric for effective classification.

We'll cover the following...
Python 3.5
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
import sklearn.metrics as metrics
df = pd.read_csv("./nonlinear.csv", sep=",", header=0)
y = df.pop("target").values
X = df
train_x, test_x, train_y, test_y = train_test_split(X,
y,
test_size=0.2,
random_state=42)
svc = SVC(kernel='rbf')
svc.fit(train_x, train_y)
pred_y = svc.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 nonlinear.csv by read_csv at line 6. Here we use the pandas library, which is a widely used library for data processing. If you are not familiar with this library, you also can check another course, ...