使用 R的mlr3proba和包运行下面的代码以在预处理数据集上实现算法并执行“可变重要性”,显示错误:mlr3pipelinesmlr3filtersrpart
task <- tsk("iris")
learner <- lrn("classif.rpart")
learner <- po("encode") %>>% po("scale") %>>% po("learner", learner) # preprocessing
learner <- GraphLearner$new(learner) #applying learner on a graph in mlr3pipelines
filter <- flt("importance", learner = learner) #using filter for variable importance
filter$calculate(task)
Run Code Online (Sandbox Code Playgroud)
#Error:
Error in learner$importance() : attempt to apply non-function
Run Code Online (Sandbox Code Playgroud)
但是当我运行上面的代码时,无需预处理,它就可以工作:
task <- tsk("iris")
learner <- lrn("classif.rpart")
filter <- flt("importance", learner = learner)
filter$calculate(task)
as.data.table(filter)
Run Code Online (Sandbox Code Playgroud)
#Results:
feature score
1: Petal.Width 88.96940
2: Petal.Length 81.34496
3: Setal.Length …Run Code Online (Sandbox Code Playgroud) 我正在学习一门有关使用 Tensorflow 进行时间序列预测的在线课程。用于将 Numpy 数组(TS)转换为 Tensorflow 数据集的函数是基于 LSTM 的模型,已经给出(带有我的注释行):
def windowed_dataset(series, window_size, batch_size, shuffle_buffer):
# creating a tensor from an array
dataset = tf.data.Dataset.from_tensor_slices(series)
# cutting the tensor into fixed-size windows
dataset = dataset.window(window_size + 1, shift=1, drop_remainder=True)
# joining windows into a batch?
dataset = dataset.flat_map(lambda window: window.batch(window_size + 1))
# separating row into features/label
dataset = dataset.shuffle(shuffle_buffer).map(lambda window: (window[:-1], window[-1]))
dataset = dataset.batch(batch_size).prefetch(1)
return dataset
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,但我想更好地理解它,以便根据我的需要修改/调整它。
如果我删除dataset.flat_map(lambda window: window.batch(window_size + 1))操作,我会收到TypeError: '_VariantDataset' object is not …
I have to do a topic modeling based on pieces of texts containing emojis with R. Using the replace_emoji() and replace_emoticon functions let me analyze them, but there is a problem with the results.
A red heart emoji is translated as "red heart ufef". These words are then treated separately during the analysis and compromise the results.
Terms like "heart" can have a very different meaning as can be seen with "red heart ufef" and "broken heart"
The function replace_emoji_identifier() …
我正在使用 python 笔记本进行 EDA 和数据科学。为此,我经常使用 dataprep 库。我想将使用该库创建的报告保存为 pdf 格式。
python data-science data-preprocessing exploratory-data-analysis
所需的任务是在 Streamlit 上部署数据预处理 Web 应用程序,用户可以在其中上传原始数据帧并下载处理后的数据帧。我正在尝试下载已完成数据预处理(例如缺失值插补)的文件,但出现如下错误:
RuntimeError: Invalid binary data format: <class 'pandas.core.frame.DataFrame'>
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题。请帮助我,因为我是 python 和 StreamLit 的新手。代码是
import streamlit as st
import pandas as pd
import os
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
temp='\\temp.csv'
path=os.getcwd()
path=path+temp
def upload_csv(zxc):
if zxc:
df=pd.read_csv(zxc)
st.dataframe(df)
df.to_csv(path,index=False)
return df
def upload_xlsx(zxc):
if zxc:
df=pd.read_excel(zxc)
st.dataframe(df)
df.to_csv(path,index=False)
return df
def mvt_mean(df):
new_df=df.fillna(df.mean())
new_df=new_df.fillna(df.select_dtypes(include='object').mode().iloc[0])
st.dataframe(new_df)
return new_df
def mvt_median(df):
new_df=df.fillna(df.median())
new_df=new_df.fillna(df.select_dtypes(include='object').mode().iloc[0])
st.dataframe(new_df)
return new_df
def mvt_mode(df):
new_df=df.fillna(df.select_dtypes(include='object').mode().iloc[0])
st.dataframe(new_df)
return new_df
def export_data():
with open('temp.csv','r+') …Run Code Online (Sandbox Code Playgroud) 我可以使用分类编码和序数编码将目标列转换为所需的有序数值。但我无法执行,inverse_transform因为显示了下面写的错误。
import pandas as pd
import category_encoders as ce
from sklearn.preprocessing import OrdinalEncoder
lst = [ 'BRANCHING/ELONGATION', 'EARLY', 'EARLY', 'EARLY', 'EARLY', 'MID', 'MID', 'ADVANCED/TILLERING',
'FLOWERING', 'FLOWERING', 'FLOWERING', 'SEEDLING/EMERGED']
filtered_df = pd.DataFrame(lst, columns =['growth_state'])
filtered_df['growth_state'].value_counts()
EARLY 4
FLOWERING 3
MID 2
ADVANCED/TILLERING 1
SEEDLING/EMERGED 1
BRANCHING/ELONGATION 1
Name: growth_state, dtype: int64
dictionary = [{'col': 'growth_state',
'mapping':{'SEEDLING/EMERGED':0, 'EARLY':1, 'MID':2,
'ADVANCED/TILLERING':3, 'BRANCHING/ELONGATION':4, 'FLOWERING':5 }}]
# instiating encoder
encoder = ce.OrdinalEncoder(cols = 'growth_state', mapping= dictionary)
filtered_df['growth_state'] = encoder.fit_transform(filtered_df['growth_state'])
filtered_df
growth_state
0 4 …Run Code Online (Sandbox Code Playgroud) python machine-learning pandas scikit-learn data-preprocessing
有理由不默认标准化所有功能吗?我意识到这对于决策树等来说可能不是必需的,但对于某些算法(例如 KNN、SVM 和 K-Means)来说可能不是必需的。定期对我的所有功能执行此操作会有什么危害吗?
另外,标准化优于规范化似乎是共识?什么时候这不是一个好主意?
我是 pandas 用户,但由于 Polars 数据帧相对于 pandas 的优势,我尝试切换到 Polars。当我进行切换时,我遇到了这样的问题:不知道如何根据另一个相关特征值用中值填充特征的空值。
如下图所示:
| 姓名 | 互联网电影数据库评分 | 元分数 |
|---|---|---|
| 乙 | 8 | 86 |
| C | 8 | 90 |
| D | 8 | 无效的 |
| 乙 | 8 | 91 |
| D | 7 | 66 |
| D | 3 | 44 |
我知道在 pandas 中我们可以做这样的事情来用中值填充“元得分”功能
df.groupby('IMDB Score')['Meta Score'].apply(lambda x: x.fillna(x.median()))
Run Code Online (Sandbox Code Playgroud)
现在我想知道我们如何在极坐标数据框中做同样的事情。
我在一个 pandas 数据框中有一个名为“date”的列名称,这是前 10 行:
0 22-Oct-2022
1 3-Dec-2019
2 27-Jun-2022
3 2023
4 15-Jul-2017
5 2019
6 7-Sep-2022
7 2021
8 30-Sep-2022
9 17-Aug-2021
Run Code Online (Sandbox Code Playgroud)
我想将所有这些日期转换为例如:
0 2023-05-19
1 2023-01-20
2 ...
Run Code Online (Sandbox Code Playgroud)
对于那些只有 YEAR 的行,我想将其设置为例如,如果原始 df 有:
0 2019
1 2021
Run Code Online (Sandbox Code Playgroud)
到
5 2019-01-01
7 2021-01-01
Run Code Online (Sandbox Code Playgroud)
换句话说,我的意思是我想在这种情况下设置今年的第一个日期,但保留原始年份而不是当前年份。
我试过:
df['date'] = pd.to_datetime(df['date'], errors='coerce', format='%d-%b-%Y')
Run Code Online (Sandbox Code Playgroud)
然而它正在生成 NaT 值。我希望你们能理解这个案例,如果有任何解决这个问题的想法,我将不胜感激
谢谢。
python ×6
pandas ×2
scikit-learn ×2
data-science ×1
download ×1
emoji ×1
mlr3 ×1
normalize ×1
r ×1
streamlit ×1
tensorflow ×1