生信拾光


  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

R语言中读取含有空白内容的数据

发表于 2020-06-28 |
字数统计: 81 | 阅读时长 ≈ 1

数据内容

image.png

导入数据:

1
test <-read.table("filename.txt",header=TRUE)

会出现错误:Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :3行没有2元素

修改:

1
test <-read.table("filename.txt",header=TRUE,fill=TRUE)

空值设为NA

na.strings = ""

1
test <-read.table("filename.txt",header=TRUE, fill=TRUE, na.strings = "")

apply家族函数的用法

发表于 2020-06-28 |
字数统计: 483 | 阅读时长 ≈ 1

apply家族函数

apply函数族是R语言中数据处理的一组核心函数,通过使用apply函数,我们可以实现对数据的循环、分组、过滤、类型控制等操作。

阅读全文 »

在R语言中替换空值

发表于 2020-06-28 |
字数统计: 269 | 阅读时长 ≈ 1

目的

如下图所示,想替换无任何字符,又不是NA的值,替换为0

image.png

阅读全文 »

正则表达式初体验

发表于 2020-06-28 |
字数统计: 284 | 阅读时长 ≈ 1

概述

正则表达式(Regular Expression)在字符串模式匹配,在字符串搜索和替换中展现强大的功能。

常用的正则表达式语法我将其总结为7类:

先看一个概括的整理

image.png

阅读全文 »

机器学习中如何处理分类变量的不均衡

发表于 2020-06-28 |
字数统计: 321 | 阅读时长 ≈ 1

Imbalanced classes put “accuracy” out of business. This is a surprisingly common problem in machine learning (specifically in classification), occurring in datasets with a disproportionate ratio of observations in each class

  • Up-sample the minority class

    • resample module with replace = True
  • Down-sample the majority class

    • resample module with replace = False
  • Change your performance metric

    • Area Under ROC Curve (AUROC)
    • from sklearn.metrics import roc_auc_score
  • Penalize algorithms (cost-sensitive training)

1
2
3
SVC(kernel='linear', 
class_weight='balanced', # penalize
probability=True)
  • Use tree-based algorithms

    • from sklearn.ensemble import RandomForestClassifier
阅读全文 »
1…678…26

六六

Seize the day! Collect the moment! Share the memory!

130 日志
5 分类
52 标签
RSS
0%
© 2023 六六 | Site words total count: 87.3k
博客全站共87.3k字