简体   繁体   English

“ValueError:无法将字符串转换为float:”机器学习拟合分类器

[英]“ValueError: could not convert string to float: ” machine learning fit classifier

When I try to fit classifier I got error: 当我尝试适合分类器时,我得到了错误:

ValueError: could not convert string to float: '4/1/2010' ValueError:无法将字符串转换为float:'4/1/2010'

# Load the Pandas libraries with alias 'pd'
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from math import sqrt
from ml_metrics import rmse

# Read data from file 'filename.csv'
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later)
data = pd.read_csv("NASDAQ.csv")
data.dropna(inplace=True)

#df.drop_duplicates(inplace=True)
nInstances, nAttributes = data.shape
if data.shape[0]:
    train = data[:1762]
    test = data[1762:]
x_train= train.values[:,0:nAttributes-1]
y_train= train.values[:,nAttributes-1]


# classifiers Linear Regression, Logistic Regression, kNN, SVM και MLP
clf = LinearRegression().fit(x_train, y_train)

could you please check this and help me out to figure where is the issue ? 请你检查一下,帮我解决问题所在?

特别是对于日期列,您可以在阅读此答案建议的csv时使用parse_dates=['column name']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:无法将字符串转换为浮点数 - 机器学习 - ValueError: could not convert string to float - machine learning 机器学习问题(解决 ValueError:无法将字符串转换为浮点数:) - Machine Learning question (Solving ValueError: could not convert string to float:) ValueError:无法将字符串转换为float:'Petal.Length'(机器学习示例) - ValueError: could not convert string to float:'Petal.Length' (machine learning example) RandomForestClassfier.fit():ValueError:无法将字符串转换为浮点数 - RandomForestClassfier.fit(): ValueError: could not convert string to float OneHotEncoder 拟合错误 ValueError:无法将字符串转换为浮点数:b - OneHotEncoder fit error ValueError: could not convert string to float: b ValueError:无法将字符串转换为float:' ' - ValueError: could not convert string to float: '���' ValueError: 无法将字符串转换为浮点数:'-' - ValueError: could not convert string to float: '-' ValueError:无法将字符串转换为浮点数:''" - ValueError: could not convert string to float: '' " ValueError:无法将字符串转换为浮点数:“否” - ValueError: could not convert string to float: 'no' ValueError: 无法将字符串转换为浮点数:'“ ”' - ValueError: could not convert string to float: '“ ”'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM