Example #1
0
def validation_curve_classifier_alt(
        path="images/validation_curve_classifier_alt.png"):
    data = pd.read_csv(os.path.join(FIXTURES, "game", "game.csv"))

    target = "outcome"
    features = [col for col in data.columns if col != target]

    X = pd.get_dummies(data[features])
    y = data[target]

    _, ax = plt.subplots()
    cv = StratifiedKFold(4)
    param_range = np.arange(3, 20, 2)

    oz = ValidationCurve(
        KNeighborsClassifier(),
        ax=ax,
        param_name="n_neighbors",
        param_range=param_range,
        cv=cv,
        scoring="f1_weighted",
        n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
Example #2
0
def validation_curve_classifier(path="images/validation_curve_classifier.png"):
    data = pd.read_csv(os.path.join(FIXTURES, "game", "game.csv"))

    target = "outcome"
    features = [col for col in data.columns if col != target]

    X = pd.get_dummies(data[features])
    y = data[target]

    _, ax = plt.subplots()
    cv = StratifiedKFold(12)
    param_range = np.logspace(-6, -1, 12)

    oz = ValidationCurve(
        SVC(),
        ax=ax,
        param_name="gamma",
        param_range=param_range,
        logx=True,
        cv=cv,
        scoring="f1_weighted",
        n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
Example #3
0
def plot_validation_curve(final_X, final_Y):

    viz = ValidationCurve(DecisionTreeClassifier(),
                          param_name="max_depth",
                          param_range=np.arange(1, 30),
                          cv=10,
                          scoring="accuracy")
    viz.fit(final_X, final_Y)
    viz.poof()
def validation_curve_sklearn_example(path="images/validation_curve_sklearn_example.png"):
    digits = load_digits()
    X, y = digits.data, digits.target

    _, ax = plt.subplots()

    param_range = np.logspace(-6, -1, 5)
    oz = ValidationCurve(
        SVC(), ax=ax, param_name="gamma", param_range=param_range,
        logx=True, cv=10, scoring="accuracy", n_jobs=4
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
Example #5
0
 def draw_validation_curve(self,
                           param_name,
                           param_range,
                           cv,
                           logx=False,
                           scoring="accuracy",
                           n_jobs=5):
     visualizer = ValidationCurve(self.model,
                                  param_name=param_name,
                                  param_range=param_range,
                                  logx=logx,
                                  cv=cv,
                                  scoring=scoring,
                                  n_jobs=n_jobs)
     visualizer.fit(self.training_data, self.training_labels)
     visualizer.poof()
Example #6
0
def validation_curve_sklearn_example(
        path="images/validation_curve_sklearn_example.png"):
    digits = load_digits()
    X, y = digits.data, digits.target

    _, ax = plt.subplots()

    param_range = np.logspace(-6, -1, 5)
    oz = ValidationCurve(SVC(),
                         ax=ax,
                         param_name="gamma",
                         param_range=param_range,
                         logx=True,
                         cv=10,
                         scoring="accuracy",
                         n_jobs=4)
    oz.fit(X, y)
    oz.poof(outpath=path)
def validation_curve_regressor(path="images/validation_curve_regressor.png"):

    data = pd.read_csv(os.path.join(FIXTURES, "energy", "energy.csv"))

    targets = ["heating load", "cooling load"]
    features = [col for col in data.columns if col not in targets]

    X = data[features]
    y = data[targets[1]]

    _, ax = plt.subplots()
    param_range = np.arange(1, 11)

    oz = ValidationCurve(
        DecisionTreeRegressor(), ax=ax, param_name="max_depth",
        param_range=param_range, cv=10, scoring="r2", n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
def validation_curve_classifier_alt(path="images/validation_curve_classifier_alt.png"):
    data = pd.read_csv(os.path.join(FIXTURES, "game", "game.csv"))

    target = "outcome"
    features = [col for col in data.columns if col != target]

    X = pd.get_dummies(data[features])
    y = data[target]

    _, ax = plt.subplots()
    cv = StratifiedKFold(4)
    param_range = np.arange(3, 20, 2)

    oz = ValidationCurve(
        KNeighborsClassifier(), ax=ax, param_name="n_neighbors",
        param_range=param_range, cv=cv, scoring="f1_weighted", n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
def validation_curve_classifier(path="images/validation_curve_classifier.png"):
    data = pd.read_csv(os.path.join(FIXTURES, "game", "game.csv"))

    target = "outcome"
    features = [col for col in data.columns if col != target]

    X = pd.get_dummies(data[features])
    y = data[target]

    _, ax = plt.subplots()
    cv = StratifiedKFold(12)
    param_range = np.logspace(-6, -1, 12)

    oz = ValidationCurve(
        SVC(), ax=ax, param_name="gamma", param_range=param_range,
        logx=True, cv=cv, scoring="f1_weighted", n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
Example #10
0
def validation_curve(model, X, y):
    from yellowbrick.model_selection import ValidationCurve
    from sklearn.model_selection import StratifiedKFold
    # Create the validation curve visualizer
    cv = StratifiedKFold(12)
    # param_range = np.linspace(30.00, 300.00, num=50.00, dtype=np.float64)
    param_range = np.logspace(30, 300, num=100, dtype=np.int32)

    viz = ValidationCurve(
        model,
        param_name="n_estimators",
        param_range=param_range,
        logx=True,
        cv=cv,
        scoring="f1_weighted",
        n_jobs=8,
    )

    viz.fit(X, y)
    viz.poof()
Example #11
0
def validation_curve_regressor(path="images/validation_curve_regressor.png"):

    data = pd.read_csv(os.path.join(FIXTURES, "energy", "energy.csv"))

    targets = ["heating load", "cooling load"]
    features = [col for col in data.columns if col not in targets]

    X = data[features]
    y = data[targets[1]]

    _, ax = plt.subplots()
    param_range = np.arange(1, 11)

    oz = ValidationCurve(
        DecisionTreeRegressor(),
        ax=ax,
        param_name="max_depth",
        param_range=param_range,
        cv=10,
        scoring="r2",
        n_jobs=8,
    )
    oz.fit(X, y)
    oz.poof(outpath=path)
plt.tight_layout()
plt.gcf().set_size_inches(10, 5)
plt.show()

# Train & Validation Curves mit yellowbricks
fig, ax = plt.subplots(figsize=(16, 9))
val_curve = ValidationCurve(
    KNeighborsRegressor(),
    param_name='n_neighbors',
    param_range=n_neighbors,
    cv=5,
    scoring=rmse_score,
    #                       n_jobs=-1,
    ax=ax)
val_curve.fit(X, y)
val_curve.poof()
fig.tight_layout()
plt.show()

fig, ax = plt.subplots(figsize=(16, 9))
l_curve = LearningCurve(
    KNeighborsRegressor(n_neighbors=best_k),
    train_sizes=np.arange(.1, 1.01, .1),
    scoring=rmse_score,
    cv=5,
    #                         n_jobs=-1,
    ax=ax)
l_curve.fit(X, y)
l_curve.poof()
fig.tight_layout()
plt.show()