博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python debug 一
阅读量:4175 次
发布时间:2019-05-26

本文共 2445 字,大约阅读时间需要 8 分钟。

1、unexpected indent

Python对代码格式是很严格的,indentation是缩进、缩排的意思,unexpected indent 就是说有“意外的”缩进。这时,就要查看自己的代码格式了!

2、invalid syntax

invalid  adj.无效的;不能成立的;

syntax  n.语法;句法;句法规则[分析];语构

invalid syntax就是无效语法。这时候,要检查自己的代码语法。

 

嘻嘻然后记入门学习NPL的今天的代码(还没搞懂代码的意思……)!

# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file.""" # -*- coding: utf-8 -*-  """  Created on Mon Aug 15 21:00:27 2016  @author: amnesia  """  	from sklearn.datasets import load_iris  iris = load_iris()  	# The feature (column) names and the response  print(iris.feature_names)print(iris.target)print(iris.target_names)	# The object types of the feature matrix and the response array  print(type(iris.data))print(type(iris.target))	# The shapes of samples and features  print(iris.data.shape)

# -*- coding: utf-8 -*-"""Created on Tue Aug 16 19:29:30 2016@author: amnesia"""from sklearn.datasets import load_iris# Import LinearSVC classfrom sklearn.svm import LinearSVC# Import KNeighborsClassifier classfrom sklearn.neighbors import KNeighborsClassifier# Load the datasetiris = load_iris()# Assign to variables for more convenient handlingX = iris.datay = iris.target# Create an instance of the LinearSVC classifierclf = LinearSVC()# Train the modelclf.fit(X, y)# Get the accuracy score of the LinearSVC classifierprint (clf.score(X, y))# Predict the response given a new observationprint (clf.predict([[ 6.3,  3.3,  6.0,  2.5]]))# Create an instance of KNeighborsClassifier# The default number of K neighbors is 5.# This can be changed by passing n_neighbors=k as argumentknnDefault = KNeighborsClassifier() # K = 5# Train the modelknnDefault.fit(X, y)# Get the accuracy score of KNeighborsClassifier with K = 5print (knnDefault.score(X, y))# Predict the response given a new observationprint (knnDefault.predict([[ 6.3,  3.3,  6.0,  2.5]]))# Let's try a different number of neighborsknnBest = KNeighborsClassifier(n_neighbors=10) # K = 10# Train the modelknnBest.fit(X, y)# Get the accuracy score of KNeighborsClassifier with K = 10print (knnBest.score(X, y))# Predict the response given a new observationprint (knnBest.predict([[ 6.3,  3.3,  6.0,  2.5]]))# Let's try a different number of neighborsknnWorst = KNeighborsClassifier(n_neighbors=100) # K = 100# Train the modelknnWorst.fit(X, y)# Get the accuracy score of KNeighborsClassifier with K = 100print (knnWorst.score(X, y))# Predict the response given a new observationprint (knnWorst.predict([[ 6.3,  3.3,  6.0,  2.5]]))

转载地址:http://ittai.baihongyu.com/

你可能感兴趣的文章
Spring框架的基本概念
查看>>
Spring Bean的配置方式及标注(Annotation)配置
查看>>
Spring框架事务管理之一:JavaEE事务与Spring事务
查看>>
java.lang.IllegalArgumentException: FacesContext must not be null 错误分析及解决
查看>>
Spring框架事务管理之四:Spring编程式事务
查看>>
JOSSO入门指南及其与WildFly AS 10的集成
查看>>
为WildFly AS 10中的Liferay Portal 6.2配置JOSSO Agent
查看>>
Spring ORM与Hibernate的集成开发详解
查看>>
WildFly AS 10中基于PicketLink的SAML SSO实现
查看>>
Spring AOP概述
查看>>
Apache Maven入门指南
查看>>
Apache Maven的插件概述
查看>>
Apache Maven项目提供的Archetype插件详解
查看>>
Apache Maven项目提供的Compiler插件详解
查看>>
Apache Maven项目提供的Ant插件详解
查看>>
Apache Maven项目提供的AntRun插件详解
查看>>
Apache Maven项目提供的EJB插件详解
查看>>
Apache Maven项目提供的JAR插件详解
查看>>
Apache Maven项目提供的WAR插件详解
查看>>
Apache Maven项目提供的EAR插件详解
查看>>