小编PL3*_*PL3的帖子

sklearn randomizedSearchCV中的参数列表,如GridSearchCV?

我有一个问题,我想测试多个不具有相同命名参数的模型.您将如何RandomizedSearchCV使用此示例中的管道参数列表GridSearchCV

示例来自:http:
//scikit-learn.org/stable/auto_examples/plot_compare_reduction.html

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_digits
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.svm import LinearSVC
from sklearn.decomposition import PCA, NMF
from sklearn.feature_selection import SelectKBest, chi2

pipe = Pipeline([
    # the reduce_dim stage is populated by the param_grid
    ('reduce_dim', None),
    ('classify', LinearSVC())
])

N_FEATURES_OPTIONS = [2, 4, 8]
C_OPTIONS = [1, 10, 100, 1000]
param_grid = [
    {
        'reduce_dim': [PCA(iterated_power=7), NMF()],
        'reduce_dim__n_components': N_FEATURES_OPTIONS, …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn

8
推荐指数
1
解决办法
975
查看次数

python正则表达式匹配并替换字符串的开头和结尾但保留中间

我有一个带有假日名称的数据框。我有一个问题,在某些日子里,假期是在不同的日子里观察到的,有时是在另一个假期的那一天。以下是一些示例问题:

1  "Independence Day (Observed)"
2  "Christmas Eve, Christmas Day (Observed)"
3  "New Year's Eve, New Year's Day (Observed)"
4  "Martin Luther King, Jr. Day"
Run Code Online (Sandbox Code Playgroud)

我想将所有 ' (Observed)' 替换为 '' 以及仅当匹配 ' (Observed)' 时逗号前的所有内容。输出应该是:

1  "Independence Day"
2  "Christmas Day"
3  "New Year's Day"
4  "Martin Luther King, Jr. Day"
Run Code Online (Sandbox Code Playgroud)

我能够独立完成这两项工作:

(foo['holiday']
 .replace(to_replace=' \(Observed\)', value='', regex=True)
 .replace(to_replace='.+, ', value='', regex=True))
Run Code Online (Sandbox Code Playgroud)

但这给“小马丁·路德·金”带来了问题。

python regex replace pandas

3
推荐指数
1
解决办法
7667
查看次数

如何使用environtment.yml文件将带有pip的本地库安装到conda环境?

我想environment.myl为项目的 conda 环境设置一个文件。我有一个通常会使用的本地包,pip install -e .因此我可以在本地处理代码。有没有办法使用 pip 用 env 文件安装这个包?

我根据使用带有 github 链接的安装选项发现的内容进行了尝试,但不起作用。

name: foo
channels:
  - defaults
dependencies:
  - python=3.7
  - pip
  - pip:
    - /Users/me/projects/package/ --install-option="-e"
Run Code Online (Sandbox Code Playgroud)

python environment yaml pip conda

3
推荐指数
1
解决办法
2236
查看次数

标签 统计

python ×3

conda ×1

environment ×1

pandas ×1

pip ×1

regex ×1

replace ×1

scikit-learn ×1

yaml ×1