虹膜数据集拆分功能不编译?

时间:2018-04-04 00:59:41

标签: python machine-learning scikit-learn train-test-split

我试图使用train_test_split函数随机分割2个数据集(numpy数组)但由于某些原因我的代码没有编译。

# Iris data set, hello world of Machine Learning
#classes: possible outcomes
#label: for each data point, its classification
# this is a three class classification problem

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

X_train, X_test,y_train y_test = train_test_split(iris_dataset['data'], 
iris_dataset['target'],random_state=0)

错误消息:

runfile('C:/Users/User/.spyder-py3/temp.py', wdir='C:/Users/User/.spyder-py3')
Traceback (most recent call last):

  File "C:\Users\User\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-63-5ba32625e270>", line 1, in <module>
    runfile('C:/Users/User/.spyder-py3/temp.py', wdir='C:/Users/User/.spyder-py3')

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/User/.spyder-py3/temp.py", line 35
    X_train, X_test,y_train y_test = train_test_split(iris_dataset['data'], iris_dataset['target'])
                                 ^
SyntaxError: invalid syntax

runfile('C:/Users/User/.spyder-py3/temp.py', wdir='C:/Users/User/.spyder-py3')
Traceback (most recent call last):

  File "C:\Users\User\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-64-5ba32625e270>", line 1, in <module>
    runfile('C:/Users/User/.spyder-py3/temp.py', wdir='C:/Users/User/.spyder-py3')

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\User\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/User/.spyder-py3/temp.py", line 35
    X_train, X_test,y_train y_test = train_test_split(iris_dataset['data'], iris_dataset['target'],random_state=0)
                                 ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:0)

y_train&amp;之间添加逗号。排队y_test

X_train, X_test,y_train y_test = train_test_split(iris_dataset['data'], 
iris_dataset['target'],random_state=0)