如何解决具有指数分布数据的激活功能
我正处于神经网络的起点,我在回归模型中有一堆目标可以预测,我注意到该模型可以完美地与已经正态分布的目标配合使用,但不适用于指数分布的目标,我知道这是激活函数规则,但是我一直在尝试许多函数(relu,linear,selu,elu等),但仍然没有得到很好的结果。
请检查下面的图像
Normally distributed
Exponentially distributed
解决方法
那是有道理的,但请给我一个谜。你采取了正确的方法吗?您不需要假设正态分布来进行回归。 OLS 以某种方式假设正态分布的数据是一个常见的误解。它不是。它要普遍得多。因此,OLS 回归不对数据做任何假设,而是对通过残差估计的误差做出假设。此外,在我看来,转换数据以适应模型是错误的方法。您希望您的模型适合您的问题,而不是相反。有几种方法可以处理倾斜的数据集。
1. Normalize Data
2. Standardize Data
让我们看一个例子。
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
##iris.keys()
df= pd.DataFrame(data= np.c_[iris['data'],iris['target']],columns= iris['feature_names'] + ['target'])
df['species'] = pd.Categorical.from_codes(iris.target,iris.target_names)
# Normalize the data attributes for the Iris dataset.
from sklearn.datasets import load_iris
from sklearn import preprocessing
import seaborn as sns
# load the iris dataset
iris = load_iris()
print(iris.data.shape)
# separate the data from the target attributes
X = df[['sepal length (cm)','sepal width (cm)','petal length (cm)','petal width (cm)']]
y = df['species']
sns.displot(X)
# normalize the data attributes
normalized_X = preprocessing.normalize(X)
sns.displot(normalized_X)
# Standardize the data attributes for the Iris dataset.
from sklearn.datasets import load_iris
from sklearn import preprocessing
# load the Iris dataset
iris = load_iris()
print(iris.data.shape)
# separate the data and target attributes
X = X
y = y
sns.displot(X)
# standardize the data attributes
standardized_X = preprocessing.scale(X)
sns.displot(standardized_X)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
iris = datasets.load_iris()
df = pd.DataFrame(iris.data,columns=iris.feature_names)
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(df[iris.feature_names],iris.target,test_size=0.5,stratify=iris.target,random_state=123456)
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(n_estimators=100,oob_score=True,random_state=123456)
rf.fit(X_train,y_train)
from sklearn.metrics import accuracy_score
predicted = rf.predict(X_test)
accuracy = accuracy_score(y_test,predicted)
print(f'Out-of-bag score estimate: {rf.oob_score_:.3}')
print(f'Mean accuracy score: {accuracy:.3}')
结果:
Out-of-bag score estimate: 0.96
Mean accuracy score: 0.933
有关这些概念的具体信息,请参阅下面的链接。
https://machinelearningmastery.com/rescaling-data-for-machine-learning-in-python-with-scikit-learn/
再说一次,也许这不是正确的方法。一方面,您可以尝试将不同的模型应用于您的特定数据集。支持向量机算法只关心分离超平面的边界,并不假设分布的确切形状。决策树系列中我最喜欢的模型之一,特别是随机森林模型。
另外,请参阅此链接,
https://www.blopig.com/blog/2017/07/using-random-forests-in-python-with-scikit-learn/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。