SyntaxError: I want to resolve invalid character identifier [overlapping]

Asked 2 years ago, Updated 2 years ago, 36 views

(Two answers) 10 months ago

I'm a beginner who just started Python last weekend.

I want to create a tool to capture data regularly and analyze it regularly, so I'm working on it while researching it.If you are familiar with it, you may be able to find out the cause right away, but I would appreciate it if you could help me.

What I've tried so far

We are proceeding with the error being crushed, but when we execute the current code, the following error message appears:

File"<ipython-input-18-06795348b04f>", line 93
    model3=DecisionTreeClassifier(criterion='entropy', max_depth=3, random_state=0)
                                                                                     ^
SyntaxError: invalid character identifier

Current Code

import pandas as pd
# Load data in Pandas.ExcelFile
input_book=pd.ExcelFile('FIFA19_data.xlsx')

input_sheet_name = input_book.sheet_names
num_sheet=len(input_sheet_name)
print(input_sheet_name)
print("Number of sheets:", num_sheet)
input_sheet_df = input_book.parse(input_sheet_name[0])

# Remove only GK data
input_sheet_df = input_sheet_df [ input_sheet_df ['Position']!="GK" ]
# Display only the first 10 lines
input_sheet_df.head(10)

import numpy as np

# load data
age=input_sheet_df.Age#age
all=input_sheet_df.Overall#comprehensive capability
message=input_sheet_df.Wage#salary
PreferredFoot=input_sheet_df.PreferredFoot#straightforward
Reputation = input_sheet_df.Reputation# Reputation
last_contract = input_sheet_df.least_contract # remaining years of engagement
crossing = input_sheet_df.Crossing #CrossingAccuracy
Finishing=input_sheet_df.Finishing#FinishingAccuracy
heading=input_sheet_df.HeadingAccuracy #HeadingAccuracy
ShortPassing=input_sheet_df.ShortPassing#ShortPassing Accuracy
Drivebling=input_sheet_df.Drivebling#DribblingAccuracy
Curve=input_sheet_df.Curve#Curve#Curve Accuracy
FKAccuracy = input_sheet_df.FKAccuracy #FK Accuracy
LongPassing=input_sheet_df.LongPassing#LongPassing #Accuracy
BallControl=input_sheet_df.BallControl#BallControl
Acceleration=input_sheet_df.Acceleration#jumpout
SprintSpeed=input_sheet_df.SprintSpeed#SprintSpeed
Agility=input_sheet_df.Agility#agility
Reactions = input_sheet_df.Reactions # Reactions
Balance=input_sheet_df.Balance#Balance
ShotPower= input_sheet_df.ShotPower#ShootPower
stamina = input_sheet_df.Stamina #stamina
Jumping=input_sheet_df.Jumping#Jump
Strength = input_sheet_df.Strength #Strength
LongShots=input_sheet_df.LongShots#LongShots
Aggression=input_sheet_df.Aggression#aggression
Interceptions=input_sheet_df.Intercepts#Intercepts
Positioning = input_sheet_df. Positioning
Vision=input_sheet_df.Vision
Penalties = input_sheet_df.Penalties
Composure=input_sheet_df.Composition
Marking = input_sheet_df.Marking
StandingTackle= input_sheet_df. StandingTackle
SlidingTackle=input_sheet_df.SlidingTackle

# specify parameters to use
equation_df2 = pd.concat([wage, age, PreferredFoot, Reputation, last_contract, \
                        crossing, finishing, heading, ShortPassing, Driving, Curve, FKAccuracy, \
                       LongPassing, BallControl, Acceleration, SprintSpeed, Agility, Reactions, \
                       Balance, ShotPower, stamina, jumping, Strength, LongShots, Aggression, \
                       Interceptions, Positioning, Vision, Penalty, Composure, Marking, \
                       StandingTackle, SlidingTackle], Axis=1)

# take out the variables to be explained
message2 = pd.DataFrame(equation_df2.Wage)
# extract the explained variable
x_list2 =equation_df2.drop("Wage", 1)

from sklearn import preprocessing, linear_model
import sklearn
import seaborn as sns

# perform data shaping
# standardize data
sc = preprocessing.StandardScaler()
sc.fit(x_list2)

X = sc.transform(x_list2)

# check the correlation coefficient

import matplotlib.pyplot asplt

plt.figure(figsize=(30,24))
sns.heatmap(x_list2.pct_change().corr(),not=True,cmap='Blues')

from sklearn import model_selection
# divide into study and test data
# Work 2:8 for split percentage
X_train, X_test, Y_train, Y_test=model_selection.train_test_split(x,wage,test_size=0.2,ramdom_state=0)

from sklearn.tree import DecisionTreeClassifier

# Conduct decision tree analysis based on X_train and Y_train values
model3=DecisionTreeClassifier(criterion='entropy', max_depth=3, random_state=0) 
model3.fit(X_train,Y_train)

print('correct answer rate (train): {:.3f}'.format(model3.score(X_train,Y_train)))
print('correct answer rate (train): {:3f}'.format(model3.score(X_test,Y_test)))

Data to load (Dropbox link)

https://www.dropbox.com/s/41lap8qzcxez33o/FIFA19_data.xlsx?dl=0

python python3 macos

2022-09-29 21:27

1 Answers

The error in question may simply be due to a full-width blank at the end of the line.

model3=DecisionTreeClassifier (criterion='entropy', max_depth=3, random_state=0) 

Please check if there is anything else like that and try to correct it.

By the way, wouldn't it save time and effort if the source code is automatically displayed, shaped, and error detected by referring to the article around here?
Make your Jupiter Notebook easier to use on your Mac [Working more efficiently] I've looked through all the enhancements in Jupiter
Jupyter A collection of TIPS that is a little convenient to know


2022-09-29 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.