Sklearn Estimators Plot Learning Curve taking a Long time to Run

Viewed 32

I feel like something is wrong, I have been running a script for almost 4 days and it hasn't finished. The part that it's stuck on is skplt.estimators.plot_learning_curve for a polynomial svc prediction. There are 20k data points, but when I run other sklearn functions on the same data set like for KNN or a neural network or decision tree, those scripts are done in less than 10 seconds. Does SVC really take that long?

Here is the full code:

from sklearn.svm import SVC
from joblib import parallel_backend
from sklearn.metrics import classification_report
import scikitplot as skplt
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import pandas as pd

star_df = pd.read_csv('data/stellar.zip', compression='zip', sep=',', low_memory=False)
star_df['class'] = star_df['class'].map({'GALAXY': 0, 'QSO': 1, 'STAR': 2})

x = star_df.filter(["u", "g", "r", "i", "z", "redshift"])
y = star_df['class']

x_train, x_test, y_train, y_test = train_test_split(x, y, stratify=y, test_size=0.20)

svc_linear = SVC(kernel='linear')
svc_poly = SVC(kernel='poly', degree=8)

y_pred_lin = None
y_pred_poly = None
with parallel_backend('threading', n_jobs=8):

    svc_linear.fit(x_train, y_train)

    y_pred_lin = svc_linear.predict(x_test)
    print(classification_report(y_test, y_pred_lin, target_names=['Galaxy', 'QSO', 'STAR']))

    svc_poly.fit(x_train, y_train)

    y_pred_poly = svc_poly.predict(x_test)
    print(classification_report(y_test, y_pred_poly, target_names=['Galaxy', 'QSO', 'STAR']))

skplt.estimators.plot_learning_curve(svc_linear, x, y,
                                     cv=7, shuffle=True, scoring="accuracy",
                                     n_jobs=-1, figsize=(6, 4), title_fontsize="large", text_fontsize="large",
                                     title="Stellar Classification Learning Curve")

As far as where the script is I have the first learning curve saved off and both print statements have come out.

0 Answers
Related