[{'role': 'system', 'content': "You are an expert in machine learning and your task is to classify code snippets into one of the following categories: ['helper_functions', 'load_data', 'data_exploration', 'data_preprocessing', 'evaluation', 'modelling', 'prediction', 'result_visualization', 'save_results', 'comment_only']."}, {'role': 'user', 'content': "Identify the single most appropriate category to which the provided code belongs. Provide your response as a single category label without any additional information, commentary, or personal opinions.\\nPython Code:'''\nI compiled the code above into a more compact function so I can cycle through different conditions/mice/etc\nas neccessary\n'''\ndef logreg_and_eval(data,num_rewards=10,test_data=False):\n'''\nPerform Logistic Regression on a pandas dataframe of trials (from feature matrix)\nInputs:\n- data: pandas dataframe of trials (from feature matrix)\nOutputs:\n- logreg: trained logistic regression model (from sklearn)\n- stats:  pandas dataframe with F1, pseudo-R2, and BIC scores from model\n- coeffs: beta coefficients from logreg\n'''\nfrom statsmodels.discrete.discrete_model import Logit\nport_features = []\nreward_features = []\nfor col in data:\nif '_Port' in col:\ndata.loc[data[col] == 0,col] = -1\nport_features.append(col)\nelif '_Reward' in col:\nreward_features.append(col)\nd = data.copy()\nfor i in range(len(port_features)):\nd[reward_features[i]] = d[reward_features[i]].values*d[port_features[i]].values\nfeatures = reward_features.copy()\nfeatures = features[-1*num_rewards:] #only take the num of rewards specificied in the function\nfeatures.append('1_Port') #append the last decision as a feature\nfeatures.append('Decision') #finally append the decision so we can take it to predict later\nd = d[features].copy() #this now just has the features we want and the decision we want to predict\nif test_data is not False:\nfor col in test_data:\nif '_Port' in col:\ntest_data.loc[test_data[col] == 0,col] = -1\ndata_test_new = test_data.copy()\nfor i in range(len(port_features)):\ndata_test_new[reward_features[i]] = test_data[reward_features[i]].values*test_data[port_features[i]].values\nd_test = data_test_new[features].copy()\nx_train = d.iloc[:,:-1].values\ny_train = d.iloc[:,-1].values\nx_test = d_test.iloc[:,:-1].values\ny_test = d_test.iloc[:,-1].values\nprev_port_test = d_test['1_Port'].values\nprev_port_test[prev_port_test==-1] = 0\nelse:\nx = d.iloc[:,:-1].values\ny = d.iloc[:,-1].values\nn_trials = x.shape[0]\nshuf_inds = np.random.permutation(n_trials)\nsplit_ind = int(n_trials*0.7)\nx_train = x[shuf_inds[:split_ind],:]\ny_train = y[shuf_inds[:split_ind]]\nx_test = x[shuf_inds[split_ind:],:]\ny_test = y[shuf_inds[split_ind:]]\nprev_port_test = d['1_Port'].values[shuf_inds[split_ind:]]\nprev_port_test[prev_port_test==-1] = 0\n'''\nModeling\n'''\nlogreg = sklearn.linear_model.LogisticRegressionCV()\nlogreg.fit(x_train,y_train)\ny_predict = logreg.predict(x_test)\ny_predict_proba = logreg.predict_proba(x_test)\nscore = logreg.score(x_test,y_test)\nmodel = Logit(y_train,x_train)\nrslt  = model.fit()\ny_test_switch = np.abs(y_test - prev_port_test)\ny_predict_switch = np.abs(y_predict - prev_port_test)\nacc_pos,acc_neg,F1=sf.score_both_and_confuse(y_predict_switch,y_test_switch,confusion=False,disp=True)\ncoefs = logreg.coef_ #retrieve coefs\ncoefs = np.append(coefs[0],logreg.intercept_) #add bias coef\nd_ = {'pseudo-R2':rslt.prsquared,'stay':acc_pos,'switch':acc_neg,'Accuracy':score,\n'BIC':rslt.bic,'negative loglikelihood':-1*rslt.llf,'F1':F1}\nstats = pd.DataFrame(data=d_,index=[0])\nfeatures = features[:-1]\nfeatures.append('Bias')\ncoefs = pd.DataFrame(data=coefs.reshape(1,-1),columns=features)\nreturn logreg,stats,coefs"}, {'role': 'assistant', 'content': 'modelling'}]