当前位置: 首页 > news >正文

中文 wordpress 主题seo公司培训课程

中文 wordpress 主题,seo公司培训课程,赤坎手机网站建设公司,搭建小程序教程《------往期经典推荐------》 一、【100个深度学习实战项目】【链接】,持续更新~~ 二、机器学习实战专栏【链接】,已更新31期,欢迎关注,持续更新中~~ 三、深度学习【Pytorch】专栏【链接】 四、【Stable Diffusion绘画系列】专…

《------往期经典推荐------》

一、【100个深度学习实战项目】【链接】,持续更新~~

二、机器学习实战专栏【链接】,已更新31期,欢迎关注,持续更新中~~
三、深度学习【Pytorch】专栏【链接】
四、【Stable Diffusion绘画系列】专栏【链接】
五、YOLOv8改进专栏【链接】持续更新中~~
六、YOLO性能对比专栏【链接】,持续更新中~

《------正文------》

目录

  • 1.原始数据分析
    • 1.1 查看数据基本信息
    • 1.2 绘图查看数据分布
  • 2.数据预处理
    • 2.1 数据特征编码与on-hot处理
  • 3.模型训练与调优
    • 3.1 数据划分
    • 3.2 模型训练调优
    • 3.3 模型评估

1.原始数据分析

1.1 查看数据基本信息

#import libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#Load Data
data = pd.read_csv('/kaggle/input/brain-tumor-dataset/brain_tumor_dataset.csv')
#insights from data
data.head()
Tumor TypeLocationSize (cm)GradePatient AgeGender
0OligodendrogliomaOccipital Lobe9.23I48Female
1EpendymomaOccipital Lobe0.87II47Male
2MeningiomaOccipital Lobe2.33II12Female
3EpendymomaOccipital Lobe1.45III38Female
4EpendymomaBrainstem6.45I35Female
data.shape
(1000, 6)

脑肿瘤的类型查看,共5种。

data['Tumor Type'].unique()
array(['Oligodendroglioma', 'Ependymoma', 'Meningioma', 'Astrocytoma','Glioblastoma'], dtype=object)
data.describe()
Size (cm)Patient Age
count1000.0000001000.000000
mean5.22150043.519000
std2.82731825.005818
min0.5100001.000000
25%2.76000022.000000
50%5.26500043.000000
75%7.69250065.000000
max10.00000089.000000
#Percentage of missing values in the dataset
missing_percentage = (data.isnull().sum() / len(data)) * 100
print(missing_percentage)
Tumor Type     0.0
Location       0.0
Size (cm)      0.0
Grade          0.0
Patient Age    0.0
Gender         0.0
dtype: float64

没有缺失数据

1.2 绘图查看数据分布

import seaborn as snsplt.figure(figsize=(10, 6))
sns.histplot(data['Patient Age'], bins=10, kde=True, color='skyblue')
plt.title('Distribution of Patient Ages')
plt.xlabel('Age')
plt.ylabel('Count')
plt.grid(True)
plt.show()

在这里插入图片描述

plt.figure(figsize=(10, 6))
sns.boxplot(x='Tumor Type', y='Size (cm)', data=data, palette='pastel')
plt.title('Tumor Sizes by Type')
plt.xticks(rotation=45)
plt.xlabel('Tumor Type')
plt.ylabel('Size (cm)')
plt.grid(True)
plt.show()

在这里插入图片描述


plt.figure(figsize=(8, 6))
sns.countplot(x='Tumor Type', data=data, palette='Set3')
plt.title('Count of Tumor Types')
plt.xlabel('Tumor Type')
plt.ylabel('Count')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()

在这里插入图片描述


plt.figure(figsize=(10, 6))
sns.scatterplot(x='Size (cm)', y='Patient Age', hue='Tumor Type', data=data, palette='Set2', s=100)
plt.title('Tumor Sizes vs. Patient Ages')
plt.xlabel('Size (cm)')
plt.ylabel('Patient Age')
plt.grid(True)
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.show()


在这里插入图片描述

location_counts = data['Location'].value_counts()
plt.figure(figsize=(8, 8))
plt.pie(location_counts, labels=location_counts.index, autopct='%1.1f%%', colors=sns.color_palette('pastel'))
plt.title('Distribution of Tumor Locations')
plt.axis('equal')
plt.show()

在这里插入图片描述

2.数据预处理

2.1 数据特征编码与on-hot处理

#Data Preprocessing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
import pandas as pddata['Gender'] = LabelEncoder().fit_transform(data['Gender'])  # Encode Gender (0 for Female, 1 for Male)
data['Location'] = LabelEncoder().fit_transform(data['Location'])  # Encode Location
data['Grade'] = LabelEncoder().fit_transform(data['Grade'])data['Tumor Type'] = LabelEncoder().fit_transform(data['Tumor Type'])  # Encode Tumor Typecolumns = ['Gender','Location','Grade']
enc = OneHotEncoder()
# 将['Gender','Location','Grade']这3列进行独热编码
new_data = enc.fit_transform(data[columns]).toarray()
new_data.shape
(1000, 12)
data.head()
Tumor TypeLocationSize (cm)GradePatient AgeGender
0439.230480
1130.871471
2332.331120
3131.452380
4106.450350
from sklearn.preprocessing import StandardScaler
# 1、实例化一个转换器类
transfer = StandardScaler()
# 2、调用fit_transform
data[['Size (cm)','Patient Age']] = transfer.fit_transform(data[['Size (cm)','Patient Age']])
old_data = data[['Tumor Type','Size (cm)','Patient Age']]
old_data.head()
one_hot_data = pd.DataFrame(new_data)
one_hot_data.head()
01234567891011
01.00.00.00.00.01.00.00.01.00.00.00.0
10.01.00.00.00.01.00.00.00.01.00.00.0
21.00.00.00.00.01.00.00.00.01.00.00.0
31.00.00.00.00.01.00.00.00.00.01.00.0
41.00.01.00.00.00.00.00.01.00.00.00.0
final_data =pd.concat([old_data, one_hot_data], axis=1)
final_data.head()
Tumor TypeSize (cm)Patient Age01234567891011
041.4184840.1792881.00.00.00.00.01.00.00.01.00.00.00.0
11-1.5398610.1392770.01.00.00.00.01.00.00.00.01.00.00.0
23-1.023212-1.2610971.00.00.00.00.01.00.00.00.01.00.00.0
31-1.334617-0.2208191.00.00.00.00.01.00.00.00.00.01.00.0
410.434728-0.3408511.00.01.00.00.00.00.00.01.00.00.00.0
final_data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 15 columns):#   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  0   Tumor Type   1000 non-null   int64  1   Size (cm)    1000 non-null   float642   Patient Age  1000 non-null   float643   0            1000 non-null   float644   1            1000 non-null   float645   2            1000 non-null   float646   3            1000 non-null   float647   4            1000 non-null   float648   5            1000 non-null   float649   6            1000 non-null   float6410  7            1000 non-null   float6411  8            1000 non-null   float6412  9            1000 non-null   float6413  10           1000 non-null   float6414  11           1000 non-null   float64
dtypes: float64(14), int64(1)
memory usage: 117.3 KB

3.模型训练与调优

3.1 数据划分

# Defining features and target
X = final_data.iloc[:,1:].values
y = final_data['Tumor Type'].values  # Example target variable# Splitting data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
X_train.shape
(800, 14)

3.2 模型训练调优

from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import classification_report, accuracy_score, confusion_matrix
import matplotlib.pyplot as plt
from sklearn.model_selection import GridSearchCVparam_grid = {'C': [0.1, 1, 10, 100],'kernel': ['linear', 'poly', 'rbf', 'sigmoid'],'degree': [3, 5]  # 仅对多项式核有效
}
grid_search = GridSearchCV(SVC(random_state=42), param_grid, cv=5, n_jobs=-1)
grid_search.fit(X_train, y_train)
best_params = grid_search.best_params_
print("Best Parameters from Grid Search:")
print(best_params)
Best Parameters from Grid Search:
{'C': 0.1, 'degree': 3, 'kernel': 'linear'}

3.3 模型评估

best_model = grid_search.best_estimator_
y_pred = best_model.predict(X_test)
print("Best Model Classification Report:")
print(classification_report(y_test, y_pred))
# Print Confusion Matrix
print(confusion_matrix(y_test, y_pred))

好了,这篇文章就介绍到这里,如果对你有帮助,感谢点赞关注!

http://www.tj-hxxt.cn/news/127145.html

相关文章:

  • 做网盘搜索网站合法吗加拿大搜索引擎
  • 做电影资源网站服务器怎么选百度一下网页入口
  • 个人网站制作说明网络营销的真实案例分析
  • 金华网站制作价格网站排名seo软件
  • 做淘宝门头的网站百度指数查询
  • 专业的做网站软件qq群引流推广软件
  • 呼和浩特网站建设哪家最便宜浙江seo博客
  • 邢台营销型网站建设网站优化seo怎么做
  • 投诉网站怎么做seo综合查询什么意思
  • 企业微信开发者工具游戏优化大师官网
  • 个人备案的网站可以做商城吗东莞优化怎么做seo
  • 网站开发工程师岗位职责seo还有哪些方面的优化
  • 网络营销网站建设诊断报告深圳关键词seo
  • 公司网站开发费用怎么做账国际新闻最新消息10条
  • 中铁中基建设集团网站seo基础
  • 网站建设收获百度一下百度一下你就知道
  • 太原做网站页面的优化设计六年级上册数学答案
  • 网上设计接单的网站站长工具域名
  • 网站建设找星火龙制作网页多少钱
  • 有了源码然后如何做网站公司seo是什么意思
  • 大连网络推广广告代理搜索引擎优化
  • 珠海品牌网站建设可以发外链的平台
  • 怎样做酒店网站ppt搜索引擎排名google
  • 大理州城乡建设局网站crm管理系统
  • 如何查询网站是否有做404厦门百度代理
  • 网站定制开发怎么做产品市场推广方案范文
  • 网站建设是否属于技术合同优化大师哪个好
  • 中关村在线小程序seo规则
  • 网站滚动效果怎么做的百度在线客服
  • 网站设计的五大要素网络推广方案