Skip to content

sklearn scale was not recognized within the bracket  #3

@pinghongyeh

Description

@pinghongyeh

Hi Gidon,

I am testing the ce_prediction scripts, but it failed in the following

for node_i in tqdm(np.arange(num_nodes)): # loop over all nodes
# a boolean vector to remove the diagonal as a feature
exclude_diag = np.ones(num_nodes, dtype=bool)
exclude_diag[node_i] = False

inputs = [x_ce[:,node_i,:], x_cm[:,node_i,exclude_diag], x_sc[:,node_i,exclude_diag]] # select a node
inputs = [scale(x) for x in inputs] # standardize the inputs (mean = 0, std = 1)

for input_i, (input_name, input_x, input_df) in enumerate(zip(input_names, inputs, dfs)): # loop over the three input types
    for ind_kf, (train_index, test_index) in enumerate(kf.split(input_x)): # the 5-fold iterator
        curr_lm = clone(lm)
        curr_lm.fit(input_x[train_index, :], y[train_index])
        y_pred_cv[input_i, test_index, node_i] = curr_lm.predict(input_x[test_index, :])
        
    # keep the pearson correlation coefficient between the real and predicted age    
    input_df.loc[node_i, 'correlation_coef'], _ = stats.pearsonr(y, y_pred_cv[input_i, :, node_i])

NameError: name 'scale' is not defined

I have run the
from matplotlib import pyplot as plt
from matplotlib.colors import rgb2hex
import numpy as np
import seaborn as sns
import pandas as pd
from scipy import stats
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.preprocessing import scale
from sklearn.model_selection import KFold
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import SGDRegressor
from sklearn.base import clone
from sklearn.metrics import explained_variance_score
from tqdm import tqdm

It seems that scale(x) does not run within the bracket []

Do you have any suggestion?
Thank you.
Ping

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions