Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
MichaelLee826
data_classification
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
data_classification
/
iris_data_classification_svm.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
45 lines (35 loc) · 1.74 KB
master
Breadcrumbs
data_classification
/
iris_data_classification_svm.py
Copy path
Top
File metadata and controls
Code
Blame
45 lines (35 loc) · 1.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pandas as pd
import numpy as np
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV, train_test_split
# def load_data(filename):
# data = np.genfromtxt(filename, delimiter=',')
# x = data[:, 1:] # 数据特征
# y = data[:, 0].astype(int) # 标签
# scaler = StandardScaler()
# x_std = scaler.fit_transform(x) # 标准化
# # 将数据划分为训练集和测试集,test_size=.3表示30%的测试集
# x_train, x_test, y_train, y_test = train_test_split(x_std, y, test_size=.3)
# return x_train, x_test, y_train, y_test
data_set = pd.read_csv('D:\\Michael\\Documents\\01 项目\\01 大数据平台\\14 数据分析\\智能装备\\测试数据\\鸢尾花\\BP神经网络\\MPL Classifier&Regression\\iris_training.csv', header=None)
x_train = data_set.ix[:, 0:3].values
y_train = data_set.ix[:, 4].values
data_test = pd.read_csv('D:\\Michael\\Documents\\01 项目\\01 大数据平台\\14 数据分析\\智能装备\\测试数据\\鸢尾花\\BP神经网络\\MPL Classifier&Regression\\iris_test.csv', header=None)
x_test = data_test.ix[:, 0:3].values
y_test = data_test.ix[:, 4].values
# rbf核函数,设置数据权重
svc = SVC(kernel='rbf', class_weight='balanced', )
c_range = np.logspace(-5, 15, 11, base=2)
gamma_range = np.logspace(-9, 3, 13, base=2)
# 网格搜索交叉验证的参数范围,cv=3,3折交叉
param_grid = [{'kernel': ['rbf'], 'C': c_range, 'gamma': gamma_range}]
grid = GridSearchCV(svc, param_grid, cv=3, n_jobs=-1)
# 训练模型
clf = grid.fit(x_train, y_train)
predict_results = clf.predict(x_test)
print(predict_results)
print(y_test)
# 计算测试集精度
score = grid.score(x_test, y_test)
print('精度为%s' % score)
You can’t perform that action at this time.