У меня есть следующий код:
df = load_data()
pd.set_option('display.max_columns', None)
df.dtypes
intBillID object
chBillChargeCode object
chBillNo object
chOriginalBillNo object
sdBillDate datetime64[ns]
sdDueDate datetime64[ns]
sdDatePaidCancelled datetime64[ns]
sdBillCancelledDate object
totalDaysToPay int64
paidInDays int64
paidOnTime int64
chBillStatus object
chBillType object
chDebtorCode object
chBillGroupCode int64
dcTotFeeBilledAmt float64
dcFinalBillExpAmt float64
dcTotProgBillAmt float64
dcTotProgBillExpAmt float64
dcReceiveBillAmt float64
dcTotWipHours float64
dcTotWipTargetAmt float64
vcReason object
OperatingUnit object
BusinessUnit object
LosCode object
dcTotNetBillAmt float64
dtype: object
Тогда у меня есть это:
# Separate features and labels
X, y = df[['totalDaysToPay', 'paidOnTime','dcTotFeeBilledAmt','dcFinalBillExpAmt','dcTotProgBillAmt', 'dcTotProgBillExpAmt','dcTotProgBillExpAmt','dcReceiveBillAmt','dcTotWipHours','dcTotWipTargetAmt']].values, df['paidInDays'].values
print('Features:',X[:10], '\nLabels:', y[:10], sep='\n')
затем я разделяю X, Y
из sklearn.model_selection import train_test_split
# Split data 70%-30% into training set and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=0)
print ('Training Set: %d rows\nTest Set: %d rows' % (X_train.shape[0], X_test.shape[0]))
Затем я хочу преобразовать числовые и категориальные функции:
# Train the model
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.linear_model import LinearRegression
import numpy as np
from sklearn.ensemble import GradientBoostingRegressor
# Define preprocessing for numeric columns (scale them)
numeric_features = [8,9,10,11,12,13,15,16,17,18,19,20,21,26]
numeric_transformer = Pipeline(steps=[
('scaler', StandardScaler())])
# Define preprocessing for categorical features (encode them)
categorical_features = [1,23,24,25]
categorical_transformer = Pipeline(steps=[
('onehot', OneHotEncoder(handle_unknown='ignore'))])
# Combine preprocessing steps
preprocessor = ColumnTransformer(
transformers=[
('num', numeric_transformer, numeric_features),
('cat', categorical_transformer, categorical_features)])
# Create preprocessing and training pipeline
pipeline = Pipeline(steps=[('preprocessor', preprocessor),
('regressor', GradientBoostingRegressor())])
# fit the pipeline to train a linear regression model on the training set
model = pipeline.fit(X_train, (y_train))
print (model)
Однако я получаю эту ошибку:
ValueError: all features must be in [0, 9] or [-10, 0]
Подробнее здесь: https://stackoverflow.com/questions/657 ... -9-or-10-0
Все функции должны быть в диапазоне [0, 9] или [-10, 0] ⇐ Python
Программы на Python
-
Anonymous
1767991046
Anonymous
У меня есть следующий код:
df = load_data()
pd.set_option('display.max_columns', None)
df.dtypes
intBillID object
chBillChargeCode object
chBillNo object
chOriginalBillNo object
sdBillDate datetime64[ns]
sdDueDate datetime64[ns]
sdDatePaidCancelled datetime64[ns]
sdBillCancelledDate object
totalDaysToPay int64
paidInDays int64
paidOnTime int64
chBillStatus object
chBillType object
chDebtorCode object
chBillGroupCode int64
dcTotFeeBilledAmt float64
dcFinalBillExpAmt float64
dcTotProgBillAmt float64
dcTotProgBillExpAmt float64
dcReceiveBillAmt float64
dcTotWipHours float64
dcTotWipTargetAmt float64
vcReason object
OperatingUnit object
BusinessUnit object
LosCode object
dcTotNetBillAmt float64
dtype: object
Тогда у меня есть это:
# Separate features and labels
X, y = df[['totalDaysToPay', 'paidOnTime','dcTotFeeBilledAmt','dcFinalBillExpAmt','dcTotProgBillAmt', 'dcTotProgBillExpAmt','dcTotProgBillExpAmt','dcReceiveBillAmt','dcTotWipHours','dcTotWipTargetAmt']].values, df['paidInDays'].values
print('Features:',X[:10], '\nLabels:', y[:10], sep='\n')
затем я разделяю X, Y
из sklearn.model_selection import train_test_split
# Split data 70%-30% into training set and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=0)
print ('Training Set: %d rows\nTest Set: %d rows' % (X_train.shape[0], X_test.shape[0]))
Затем я хочу преобразовать числовые и категориальные функции:
# Train the model
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.linear_model import LinearRegression
import numpy as np
from sklearn.ensemble import GradientBoostingRegressor
# Define preprocessing for numeric columns (scale them)
numeric_features = [8,9,10,11,12,13,15,16,17,18,19,20,21,26]
numeric_transformer = Pipeline(steps=[
('scaler', StandardScaler())])
# Define preprocessing for categorical features (encode them)
categorical_features = [1,23,24,25]
categorical_transformer = Pipeline(steps=[
('onehot', OneHotEncoder(handle_unknown='ignore'))])
# Combine preprocessing steps
preprocessor = ColumnTransformer(
transformers=[
('num', numeric_transformer, numeric_features),
('cat', categorical_transformer, categorical_features)])
# Create preprocessing and training pipeline
pipeline = Pipeline(steps=[('preprocessor', preprocessor),
('regressor', GradientBoostingRegressor())])
# fit the pipeline to train a linear regression model on the training set
model = pipeline.fit(X_train, (y_train))
print (model)
Однако я получаю эту ошибку:
ValueError: all features must be in [0, 9] or [-10, 0]
Подробнее здесь: [url]https://stackoverflow.com/questions/65789613/all-features-must-be-in-0-9-or-10-0[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия