简体   繁体   中英

“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'

# 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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM