PridaLab / rippl-AI

A open toolbox of several machine learning approaches for sharp-wave ripple detection
26 stars 4 forks source link

Marmotiaaa #6

Open Marmotiaaa opened 1 week ago

Marmotiaaa commented 1 week ago

Hi! I want to test the Get performances after detection part in the jupyter notebook example_detections. I downloaded and loaded the data successfully, but when I ran this session:

# Two loops going over every possible model
architectures=['XGBOOST','SVM','LSTM','CNN1D','CNN2D']
SWR_prob=[[None]*5]*5
for i,architecture in enumerate(architectures):
    print(i,architecture)
    for n in range(1,6):
        # Make sure the selected model expected number of channels is the same as the channels array passed to the predict fcn
        # In this case, we are manually setting the channel array to 3 
        if architecture=='CNN2D' and n>=3:
            channels=[0,3,7]
        else:
            channels=[0,1,2,3,4,5,6,7]
        SWR_prob[i][n-1],_=rippl_AI.predict(LFP,sf,arch=architecture,model_number=n,channels=channels)

# SWR_prob contains the output of each model

I met the following problems:

{
    "name": "AttributeError",
    "message": "'_CalibratedClassifier' object has no attribute 'base_estimator'",
    "stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[24], line 13
     11         else:
     12             channels=[0,1,2,3,4,5,6,7]
---> 13         SWR_prob[i][n-1],_=rippl_AI.predict(LFP,sf,arch=architecture,model_number=n,channels=channels)
     15 # SWR_prob contains the output of each model

File f:\\code\\rippl-AI\\rippl-AI\\rippl_AI.py:88, in predict(LFP, sf, d_sf, arch, model_number, channels, new_model, n_channels, n_timesteps)
     86 else: # Data is supossedly already normalized when using new model
     87     norm_LFP=LFP
---> 88 prob=prediction_parser(norm_LFP,arch,model_number,new_model,n_channels,n_timesteps)
     90 return(prob,norm_LFP)

File f:\\code\\rippl-AI\\rippl-AI\\aux_fcn.py:420, in prediction_parser(LFP, arch, model_number, new_model, n_channels, n_timesteps)
    418 else:
    419     clf=new_model
--> 420 windowed_signal= clf.predict_proba(LFP)[:,1]
    421 for i,window in enumerate(windowed_signal):
    422     y_predict[i*timesteps:(i+1)*timesteps]=window

File c:\\Software\\Anaconda\\envs\\rippl_AI_env\\lib\\site-packages\\sklearn\\calibration.py:433, in CalibratedClassifierCV.predict_proba(self, X)
    431 mean_proba = np.zeros((_num_samples(X), len(self.classes_)))
    432 for calibrated_classifier in self.calibrated_classifiers_:
--> 433     proba = calibrated_classifier.predict_proba(X)
    434     mean_proba += proba
    436 mean_proba /= len(self.calibrated_classifiers_)

File c:\\Software\\Anaconda\\envs\\rippl_AI_env\\lib\\site-packages\\sklearn\\calibration.py:713, in _CalibratedClassifier.predict_proba(self, X)
    697 \"\"\"Calculate calibrated probabilities.
    698 
    699 Calculates classification calibrated probabilities
   (...)
    710     The predicted probabilities. Can be exact zeros.
    711 \"\"\"
    712 n_classes = len(self.classes)
--> 713 pred_method, method_name = _get_prediction_method(self.base_estimator)
    714 predictions = _compute_predictions(pred_method, method_name, X, n_classes)
    716 label_encoder = LabelEncoder().fit(self.classes)

AttributeError: '_CalibratedClassifier' object has no attribute 'base_estimator'"
}

What might be causing this issue? Thanks for answering!

adrubio999 commented 18 hours ago

Hi @Marmotiaaa , thank you for using Ripple-AI.

Considering the error message, it might be caused by a sklearn version discrepancy. Did you follow the Enviroment setup section at the end of the README.md? Please let me know.