首页 > 其他分享 >20240117进度汇报

20240117进度汇报

时间:2024-01-21 22:25:56浏览次数:30  
标签:iris svc print 汇报 train 20240117 test import 进度

 

#!/usr/bin/env python

from __future__ import print_function

import collections
import csv
import logging
import os

import SimpleITK as sitk

import radiomics
from radiomics import featureextractor


def main():
  outPath = r''

  inputCSV = os.path.join(outPath, 'testCases.csv')
  outputFilepath = os.path.join(outPath, 'radiomics_features.csv')
  progress_filename = os.path.join(outPath, 'pyrad_log.txt')
  params = os.path.join(outPath, 'exampleSettings', 'Params.yaml')

  # Configure logging
  rLogger = logging.getLogger('radiomics')

  # Set logging level
  # rLogger.setLevel(logging.INFO)  # Not needed, default log level of logger is INFO

  # Create handler for writing to log file
  handler = logging.FileHandler(filename=progress_filename, mode='w')
  handler.setFormatter(logging.Formatter('%(levelname)s:%(name)s: %(message)s'))
  rLogger.addHandler(handler)

  # Initialize logging for batch log messages
  logger = rLogger.getChild('batch')

  # Set verbosity level for output to stderr (default level = WARNING)
  radiomics.setVerbosity(logging.INFO)

  logger.info('pyradiomics version: %s', radiomics.__version__)
  logger.info('Loading CSV')

  flists = []
  try:
    with open(inputCSV, 'r') as inFile:
      cr = csv.DictReader(inFile, lineterminator='\n')
      flists = [row for row in cr]
  except Exception:
    logger.error('CSV READ FAILED', exc_info=True)

  logger.info('Loading Done')
  logger.info('Patients: %d', len(flists))

  if os.path.isfile(params):
    extractor = featureextractor.RadiomicsFeatureExtractor(params)
  else:  # Parameter file not found, use hardcoded settings instead
    settings = {}
    settings['binWidth'] = 25
    settings['resampledPixelSpacing'] = None  # [3,3,3]
    settings['interpolator'] = sitk.sitkBSpline
    settings['enableCExtensions'] = True

    extractor = featureextractor.RadiomicsFeatureExtractor(**settings)
    extractor.enableInputImages(wavelet= {'level': 2})

  logger.info('Enabled input images types: %s', extractor.enabledImagetypes)
  logger.info('Enabled features: %s', extractor.enabledFeatures)
  logger.info('Current settings: %s', extractor.settings)

  headers = None

  for idx, entry in enumerate(flists, start=1):

    logger.info("(%d/%d) Processing Patient (Image: %s, Mask: %s)", idx, len(flists), entry['Image'], entry['Mask'])

    imageFilepath = entry['Image']
    maskFilepath = entry['Mask']
    label = entry.get('Label', None)

    if str(label).isdigit():
      label = int(label)
    else:
      label = None

    if (imageFilepath is not None) and (maskFilepath is not None):
      featureVector = collections.OrderedDict(entry)
      featureVector['Image'] = os.path.basename(imageFilepath)
      featureVector['Mask'] = os.path.basename(maskFilepath)

      try:
        featureVector.update(extractor.execute(imageFilepath, maskFilepath, label))

        with open(outputFilepath, 'a') as outputFile:
          writer = csv.writer(outputFile, lineterminator='\n')
          if headers is None:
            headers = list(featureVector.keys())
            writer.writerow(headers)

          row = []
          for h in headers:
            row.append(featureVector.get(h, "N/A"))
          writer.writerow(row)
      except Exception:
        logger.error('FEATURE EXTRACTION FAILED', exc_info=True)

if __name__ == '__main__':
  main()

 

from sklearn import feature_selection
from sklearn import datasets

# 初始化鸢尾花数据集
iris = datasets.load_iris()
# 初始化转换器(指定方差为0.2)
vt = feature_selection.VarianceThreshold(threshold=0.2)

# 使用转换器对数据进行低方差过滤
result = vt.fit_transform(iris.data)

# 打印数据特征
print(result)
print(result.shape)
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
#load data 
iris = load_iris()  
Y = iris.target  
X = iris.data  
print(X.shape)
X_new = SelectKBest(chi2, k=2).fit_transform(X, Y)
print(X_new.shape)

 

import sklearn
from sklearn.linear_model import Lasso,LassoCV,LassoLarsCV
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np

iris = load_iris()  
Y = iris.target  
X = iris.data  

X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.3)

alphas = np.logspace(-3,1,50)
model_lassoCV = LassoCV(alphas = alphas, cv = 10, max_iter = 100000).fit(X_train,Y_train)
acc_lasso = model_lassoCV.score(X_test,Y_test)

print(model_lassoCV.coef_)
print(acc_lasso)

 

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
from sklearn.model_selection import train_test_split
from sklearn import svm
import pandas as pd

#load data 
iris = load_iris()  
Y = iris.target  
print(Y)
X = iris.data  
print(X)
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.3)

#PCA
pca = PCA(n_components=0.99)
pca = pca.fit(X_train)  
print(pca.explained_variance_)
print(pca.explained_variance_ratio_)
X_train_pca = pca.transform(X_train)
print(X_train_pca)
X_test_pca = pca.transform(X_test)
print(X_test_pca)

#SVM
lin_svc = svm.SVC(kernel='linear').fit(X_train_pca,Y_train)
rbf_svc = svm.SVC(kernel='rbf').fit(X_train_pca,Y_train)
poly_svc = svm.SVC(kernel='poly',degree=3).fit(X_train_pca,Y_train)

lin_svc_pre = lin_svc.predict(X_test_pca)
rbf_svc_pre = rbf_svc.predict(X_test_pca)
poly_svc_pre = poly_svc.predict(X_test_pca)

acc_lin_svc = lin_svc.score(X_test_pca,Y_test)
acc_rbf_svc = rbf_svc.score(X_test_pca,Y_test)
acc_poly_svc = poly_svc.score(X_test_pca,Y_test)


print('acc_lin_svc: ',acc_lin_svc)
print('acc_lin_predicted: ',lin_svc_pre)
print('acc_rbf_svc: ',acc_rbf_svc)
print('acc_rbf_predicted: ',rbf_svc_pre)
print('acc_poly_svc: ',acc_poly_svc)
print('acc_poly_predicted: ',poly_svc_pre)

 

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
from sklearn.model_selection import train_test_split
from sklearn import svm
import pandas as pd
from sklearn.ensemble import RandomForestClassifier

#load data 
iris = load_iris()  
Y = iris.target  
X = iris.data  
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.3)

clf = RandomForestClassifier(n_estimators=5)
clf.fit(X_train, Y_train)
score = clf.score(X_test, Y_test)
print("模型测试集准确率为:", score)
print('特征重要程度: ',clf.feature_importances_)

 

 

标签:iris,svc,print,汇报,train,20240117,test,import,进度
From: https://www.cnblogs.com/YuhangLiuCE/p/17978556

相关文章

  • 大三寒假学习进度笔记11
    今日对之前学习的pyspark内容进行了梳理,同时尝试了通过SparkSQL的JDBC方式从mysql读取数据和写入数据#coding:utf8frompyspark.sqlimportSparkSessionfrompyspark.sql.typesimportStructType,StringType,IntegerTypeimportpandasaspdif__name__=='__main__......
  • 同时上传多个文件实现,带进度条(完整代码)
    单文件上传先简单来定义一个表单,注意加enctype=“multipart/form-data”,表示是上传组件<formenctype="multipart/form-data"id="formData">MultipartFile:<inputtype="file"name="file"id="fileName1"/><br><di......
  • 1/20 学习进度笔记
    完成了搜索引擎日志分析小案例数据由两万条一下六列相同格式的单个数据组成 分别对应:搜索时间  用户ID搜索内容URL返回排名用户点击顺序用户点击的URL 使用到了python的jieba插件进行热词的分析TODO:需求1:用户搜索关键‘词’分析需求1结果:[('sc......
  • 1.20学习进度
    1.standaloneHA的运行原理:为解决单点故障问题,spark由两种方案:基于文件系统的单点恢复(只能用于开发或测试环境)、基于zookeeper的standbymaster(可以用于生产环境);基于zookeeper做状态的维护,开启多个master进程,一个作为活跃,其他的作为备份,当活跃进程宕机,备份master进行接管第五章1.......
  • 1/19 学习进度笔记
    1.Cache和Checkpoint区别Cache是轻量化保存RDD数据,可存储在内存和硬盘,是分散存储,设计上数据是不安全的(保留RDD血缘关系)CheckPoint是重量级保存RDD数据,是集中存储,只能存储在硬盘(HDFS)上,设计上是安全的(不保留RDD血缘关系)2.Cache和CheckPoint的性能对比?Cache性能更好,因为......
  • 大三寒假学习进度笔记10
    今日学习SprackSQL的两种语言风格,分别是DLS风格和SQL风格,其中SQL风格的语句需要先将DataFrame注册成表才能使用接下来是学习中使用到的部分代码#coding:utf8frompyspark.sqlimportSparkSessionfrompyspark.sql.typesimportStructType,StringType,IntegerTypeimpor......
  • 1.19学习进度
    1.standalone是一个完整的分布式集群环境;standalone集群在进程上主要有三类进程:主节点master及昵称、从节点的worker进程、历史服务器哦historyserver(可选)2.4040:是一个运行的application在运行的过程中临时绑定的端口,用以查看当前任务的状态。4040被占用会顺延到4041、4042等。404......
  • 大三寒假学习进度笔记9
    今日学习时间一小时,学习内容:通过不同格式构建DataFrame对象,包括基于Pandas的DF转换,读取text,csv,json和jparquet创建。jparquet具有以下特点:列式存储自带Schema具备PredicateFilter特性一个Parquet文件的内容由Header、DataBlock和Footer三部分组成。在文件的首尾各有一个......
  • 2024/1/18学习进度笔记
    今天研究了外包杯的题目。我们做的主要是一个虚拟数字人的项目,这里记录下在windows上配置pytorch3d以及freqencoder,gridencoder,raymarchingshencoder这几个库的过程首先这几个库是用过setup.py进行安装的,也就是pythonsetup.pyinstall安装前电脑里必须要装好了VisualStu......
  • 2024.1.18-每日进度笔记
    今天,我主要尝试了通过摄像头拍照并保存在本地指定文件。 参考:百度文心一言的回复。 <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><html><head><title>获取摄像头画面并拍照</title......