def part_plot_1D(model, total_features, X_val, y_val, feature):
    pdp_dist = pdp.pdp_isolate(model=model,
                               dataset=X_val,
                               model_features=total_features,
                               feature=feature)
    pdp.pdp_plot(pdp_dist, feature)
    plt.show()
Beispiel #2
0
def plot_pdp(m,
             X,
             features,
             feature,
             center=True,
             classes=None,
             percentile_range=None,
             plot_params=None):
    p = pdp.pdp_isolate(m,
                        X,
                        features,
                        feature,
                        n_jobs=-1,
                        percentile_range=percentile_range)
    fig, axes = pdp.pdp_plot(p,
                             feature,
                             plot_lines=True,
                             center=center,
                             plot_pts_dist=True,
                             plot_params=plot_params)
    if classes is not None:
        _ = axes['pdp_ax']['_pdp_ax'].set_xticklabels(classes)
        _ = axes['pdp_ax']['_count_ax'].set_xticklabels(classes)
        _ = axes['pdp_ax']['_count_ax'].set_xlabel('')
        _ = axes['pdp_ax']['_count_ax'].set_title('')
        fig.autofmt_xdate()
    plt.show()
def plot_pdp(feat, clusters=None, feat_name=None):
    feat_name = feat_name or feat
    p = pdp.pdp_isolate(m, x, feat)
    return pdp.pdp_plot(p,
                        feat_name,
                        plot_lines=True,
                        cluster=clusters is not None,
                        n_cluster_centers=clusters)
Beispiel #4
0
def partial_dependence_plot(model, data: pd.DataFrame, model_features: list,
                            column: str):
    pdp_df = pdp.pdp_isolate(model=model,
                             dataset=data,
                             model_features=model_features,
                             feature=column)
    pdp.pdp_plot(pdp_df, column, figsize=(10, 8))
    return plt.show()
Beispiel #5
0
def generateInsight(model,features,data):
    pdp_airbnb = pdp.pdp_isolate(model=model,
                               dataset=data,
                               model_features=data.columns,
                               feature=features)
    fig, axes = pdp.pdp_plot(pdp_isolate_out=pdp_airbnb,
                             feature_name=features,
                             plot_pts_dist=True, 
                             )
Beispiel #6
0
def plot_pdp(df, model, feat, clusters=None, feat_name=None):
    '''Use a sample from the dataframe using get_sample()'''
    feat_name = feat_name or feat
    p = pdp.pdp_isolate(model, df, df.columns, feat)
    return pdp.pdp_plot(p,
                        feat_name,
                        plot_lines=True,
                        cluster=clusters is not None,
                        n_cluster_centers=clusters)
Beispiel #7
0
def partial_dependence_plot(feat_name, model, X_test, base_features, path):
    pdp_dist = pdp.pdp_isolate(model=model,
                               dataset=X_test,
                               model_features=base_features,
                               feature=feat_name)
    pdp.pdp_plot(pdp_dist, feat_name)
    plt.savefig(path)
    print('generate ' + path)
    plt.close()
Beispiel #8
0
def ploting_pdp(f):
    ''' Function for ploting PDP '''
    pdp_surv = pdp.pdp_isolate(model=rf,
                               dataset=X_train,
                               model_features=X_train.columns,
                               feature=f,
                               cust_grid_points=None)
    pdp.pdp_plot(pdp_surv, f)
    plt.show()
def plot_1D_partial_dependency(fitted_model, X_test : pd.DataFrame, model_features : list, feature : str ):
	# Create the data that we will plot
	pdp_obj = pdp.pdp_isolate(model = fitted_model,
								dataset = X_test,
								model_features = model_features,
								feature = feature)

	# plot it
	pdp.pdp_plot(pdp_obj, feature)
	plt.show()
def show_partial_dep_plots(lin_model, X_test):
    """Prints partial dependence plots for each feature in the dataset."""
    for feat_name in X_test.columns:
        pdp_dist = pdp.pdp_isolate(
            model=lin_model,
            dataset=X_test,
            model_features=X_test.columns,
            feature=feat_name,
        )
        pdp.pdp_plot(pdp_dist, feat_name)
        plt.show()
def plot_pdp(model, x, feat, clusters=None, feat_name=None, filename=None):
    feat_name = feat_name or feat
    p = pdp.pdp_isolate(model, x, x.columns, feat)
    fig, ax = pdp.pdp_plot(p,
                           feature_name=feat_name,
                           plot_lines=True,
                           cluster=clusters is not None,
                           n_cluster_centers=clusters)
    if filename:
        pdp.plt.savefig(filename + '.png', dpi=200)
    pdp.plt.show()
    return fig
Beispiel #12
0
def isolated(model, X, feature):
    """
    isolated pair dependancy plot
    """

    #instantiate and isolate variable
    isolated = pdp_isolate(model = model,
                        dataset = X,
                        model_features = X.columns,
                        feature = feature)
    #plot the variable
    pdp_plot(isolated, feature_name = feature)
def pdpplot(feature_to_plot,
            pdp_model=random_forest,
            pdp_dataset=X_test,
            pdp_model_features=list(X)):
    pdp_cancer = pdp.pdp_isolate(model=pdp_model,
                                 dataset=pdp_dataset,
                                 model_features=pdp_model_features,
                                 feature=feature_to_plot)
    fig, axes = pdp.pdp_plot(pdp_cancer,
                             feature_to_plot,
                             figsize=(10, 5),
                             plot_params={})
Beispiel #14
0
    def plot_pdp(self, feature_to_plot, i):
        # creating data to plot
        pdp_feature = pdp.pdp_isolate(model=self.model,
                                      dataset=self.x,
                                      model_features=list(self.x.columns),
                                      feature=feature_to_plot)

        # plot it
        pdp.pdp_plot(pdp_feature, feature_to_plot)

        # saving the plot
        plt.tight_layout()
        plt.savefig(self.out + '/dep_plot' + str(i) + '.jpg', dpi=400)
        plt.close()