Output exceeds the size limit. Open the full output data in a text…
- User
Output exceeds the size limit. Open the full output data in a text editor--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_15140\2407638867.py in 50 51 delta_gini_target = 10 ---> 52 get_delta_gini(rd, delta_gini_target)
~\AppData\Local\Temp\ipykernel_15140\2407638867.py in get_delta_gini(rd, delta_gini_target) 28 print(adjusted_proba) 29 adjusted_proba = preprocessing.normalize([adjusted_proba]) ---> 30 adjusted_proba = get_calibrated_score(adjusted_proba) 31 adjusted_proba = np.clip(adjusted_proba, 0, 1) 32 # print(adjusted_proba)
~\AppData\Local\Temp\ipykernel_15140\1123040768.py in get_calibrated_score(score) 8 y_train = rd.target_orm 9 # Train the logistic regression model on the original training data ---> 10 logreg.fit(X_train, y_train) 11 12 # Initialize the CalibratedClassifierCV with the trained logistic regression model
~\AppData\Roaming\Python\Python39\site-packages\sklearn\linear_model_logistic.py in fit(self, X, y, sample_weight) 1506 _dtype = [np.float64, np.float32] 1507 -> 1508 X, y = self._validate_data( ... --> 332 raise ValueError( 333 "Found input variables with inconsistent numbers of samples: %r" 334 % [int(l) for l in lengths]
ValueError: Found input variables with inconsistent numbers of samples: [1, 58799]
- Assistant
- User
def get_calibrated_score(score): # Initialize the logistic regression model logreg = LogisticRegression()
X_train = pd.DataFrame(score, index=range(len(score))).rename(columns={0:'score'}) # X_train = pd.DataFrame(score) # display(X_train) y_train = rd.target_orm # Train the logistic regression model on the original training data logreg.fit(X_train, y_train) # Initialize the CalibratedClassifierCV with the trained logistic regression model clf = CalibratedClassifierCV(logreg, method='sigmoid').fit(X_train, y_train) # Get the predicted probabilities for the training data calibrated_probs_train = clf.predict_proba(X_train) return calibrated_probs_train[:, 1] - Assistant
- User
~\AppData\Local\Temp\ipykernel_15140\3214441376.py in get_calibrated_score(score) 11 y_train = rd.target_orm 12 # Train the logistic regression model on the original training data ---> 13 logreg.fit(X_train, y_train) 14 15 # Initialize the CalibratedClassifierCV with the trained logistic regression model
~\AppData\Roaming\Python\Python39\site-packages\sklearn\linear_model_logistic.py in fit(self, X, y, sample_weight) 1506 _dtype = [np.float64, np.float32] 1507 -> 1508 X, y = self._validate_data( ... --> 332 raise ValueError( 333 "Found input variables with inconsistent numbers of samples: %r" 334 % [int(l) for l in lengths]
ValueError: Found input variables with inconsistent numbers of samples: [1, 58799] Как сделать reshape 1 веткора так, чтобы функция приведенная выше сработала?
- Assistant
Прежде всего стоит отметить, что обучение модели логистической регрессии и калибровка вероятностей не могут быть выполнены должным образом с использованием всего лишь одного вектора признаков (
score). В обучении моделей машинного обучения требуется использовать набор данных с множеством примеров (со многими векторами признаков), чтобы модель могла обучиться и обобщить закономерности из этих данных.Ваша функция
get_calibrated_scoreнаправлена на использованиеCalibratedClassifierCVдля калибровки уже обученной модели, но вы передаете ей лишь один вектор признаков (). Вместо этого, вам нужно обучить модель на наборе данных, затем калибровать ее с помощью отдельного набора данных (что часто является частью валидационного разделения).