在rails中生成一个外部url(Generating an external url in rails)
我想在我的Rails应用程序中构建一个指向另一个不运行rails的服务器的url。 使用
url_for
几乎可以满足我的要求,但它需要一个我不需要的控制器键(重定向到外部站点的顶级页面)。我想这样做的原因是我有一个干净的构造URL的散列参数(其中一些是在运行时确定的)。
I want to construct a url within my rails app that points to another server that isn't running rails. Using
url_for
almost satisfies my requirements, but it requires a controller key which I don't need (redirecting to a top level page on the external site).The reason I want to do this is so that I have a cleanly construct a url with a hash of arguments (some of which are determined at runtime).
原文:https://stackoverflow.com/questions/1479829
最满意答案
手动地,您可以使用
pd.DataFrame
构造函数,给出一个numpy数组(data
)和一列列(columns
)的名称。 要将所有内容都放在一个DataFrame中,可以使用np.c_[...]
(请注意[]
将np.c_[...]
和目标连接成一个numpy数组:import numpy as np import pandas as pd from sklearn.datasets import load_iris # save load_iris() sklearn dataset to iris # if you'd like to check dataset type use: type(load_iris()) # if you'd like to view list of attributes use: dir(load_iris()) iris = load_iris() # np.c_ is the numpy concatenate function # which is used to concat iris['data'] and iris['target'] arrays # for pandas column argument: concat iris['feature_names'] list # and string list (in this case one string); you can make this anything you'd like.. # the original dataset would probably call this ['Species'] data1 = pd.DataFrame(data= np.c_[iris['data'], iris['target']], columns= iris['feature_names'] + ['target'])
Manually, you can use
pd.DataFrame
constructor, giving a numpy array (data
) and a list of the names of the columns (columns
). To have everything in one DataFrame, you can concatenate the features and the target into one numpy array withnp.c_[...]
(note the[]
):import numpy as np import pandas as pd from sklearn.datasets import load_iris # save load_iris() sklearn dataset to iris # if you'd like to check dataset type use: type(load_iris()) # if you'd like to view list of attributes use: dir(load_iris()) iris = load_iris() # np.c_ is the numpy concatenate function # which is used to concat iris['data'] and iris['target'] arrays # for pandas column argument: concat iris['feature_names'] list # and string list (in this case one string); you can make this anything you'd like.. # the original dataset would probably call this ['Species'] data1 = pd.DataFrame(data= np.c_[iris['data'], iris['target']], columns= iris['feature_names'] + ['target'])
相关问答
更多-
如何将Scikit-learn数据集转换为Pandas数据集?(How to convert a Scikit-learn dataset to a Pandas dataset?)[2023-03-31]
手动地,您可以使用pd.DataFrame构造函数,给出一个numpy数组( data )和一列列( columns )的名称。 要将所有内容都放在一个DataFrame中,可以使用np.c_[...] (请注意[]将np.c_[...]和目标连接成一个numpy数组: import numpy as np import pandas as pd from sklearn.datasets import load_iris # save load_iris() sklearn dataset to iri ... -
Scikit-从分段时间序列中学习标记的数据集创建(Scikit-learn labeled dataset creation from segmented time series)[2022-11-07]
这不是微不足道的,可能有几种方法可以通过ML算法来制定消费问题。 您应该尝试所有这些并找到如何获得最佳结果。 正如您已经发现的那样,您需要两件事,一个形状为n_samples * n_features的矩阵X和一个长度为'n_samples'的列向量y 。 让我们从目标y开始。 目标: 由于您希望从离散的用户名池中预测用户,因此您有一个分类问题,您的目标将是一个带有np.unique(y) == ['user1', 'user2', ...]的向量 特征 您的功能是为每个标签/用户/目标提供ML算法的信息。 ... -
使用scikit-learn处理带有大数据集6gb的K-means?(Handling K-means with large dataset 6gb with scikit-learn?)[2023-06-07]
将MiniBatchKMeans与HashingVectorizer一起使用; 这样,您可以在数据的单次传递中学习群集模型,在您进行或第二次传递时分配群集标签。 有一个演示MBKM的示例脚本 。 Use MiniBatchKMeans together with HashingVectorizer; that way, you can learn a cluster model in a single pass over the data, assigning cluster labels as you g ... -
GridSearchCV在scikit-learn中的小数据集上极其缓慢(GridSearchCV extremely slow on small dataset in scikit-learn)[2022-06-26]
如前所述,对于基于SVM的分类器(如y == np.int* ), 预处理是必须的 ,否则ML-Estimator的预测能力会因偏斜特征对decission函数的影响而丢失。 由于反对处理时间: 试着更好地了解你的AI / ML-Model Overfit / Generalization [C,gamma]景观 尝试在初始AI / ML过程调整中添加详细程度 尝试将n_jobs添加到数字运算中 如果规模要求,尝试将网格计算添加到您的计算方法中 。 aGrid = aML_GS.GridSearchCV( ... -
我建议使用sklearn的train_test_split from sklearn.cross_validation import train_test_split X, y = dataset.iloc[:,:-1], dataset.iloc[:, -1] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1) I'd recommend using sklearn's trai ...
-
处理scikit-learn MLPClassifier的分类类标签(Handle categorical class labels for scikit-learn MLPClassifier)[2022-07-04]
您可能需要预处理数据,因为scikit-learn只处理数字值。 在这种情况下,我想预测交易的货币。 该货币用ISO代码表示,因此LabelEncoder被用于将其转换为数字类别(即:1,2,3 ...): #Import the object LabelEncoder from sklearn.preprocessing import LabelEncoder #defining class column my_encoder = LabelEncoder() my_class_currency = n ... -
将分类数据转换为数字数据scikit-learn optimization(Convert categorical data to be numeric data scikit-learn optimization)[2023-08-12]
升级scikit-learn 将稀疏变为true vect = DictVectorizer(sparse = False) upgrade scikit-learn change sparse to true vect = DictVectorizer(sparse=False) -
您必须除以应用的缩放以标准化要素,还要乘以应用于目标的缩放。 假设 每个特征变量x_i由scale_x_i缩放(除) 目标变量由scale_y缩放(除) 然后 orig_coef_i = coef_i_found_on_scaled_data / scale_x_i * scale_y 这是使用pandas和sklearn LinearRegression的示例 from sklearn.datasets import load_boston from sklearn.linear_model impor ...
-
如何使用scikit-learn的XGBRegressor缺失参数(How to use missing parameter of XGBRegressor of scikit-learn)[2022-03-20]
我的理解是你搞砸了。 缺失参数仅替换缺失的某个值(或值列表)(也称为NaN) - 默认值为“np.nan” 如果你想要替换某些不同值的实际缺失值,那么在应用模型之前,你要说“X”你必须对你的数据做。 如果你有一个数据帧“df”,你可以: df.fillna(X) 如果你有一个np.array“数组”你可以: np.nan_to_num(array) 但以上将用零替换np.nan。 希望有所帮助, The missing value parameter works as whatever value yo ... -
对于scikit学习分类器,数据以形状矩阵[n_samples, n_features]的形式表示,正如您所说的那样。 不需要样本索引(如果你需要一个用于其他目的,不要将它放在你打算传递给scikit学习的矩阵中)。 举个例子,一个样本就是 samples = [[0.162, 0.168, 0.250, 0.114, 0.106, 0.044, 0.035, 0.059, 0.200, 0.149]] 这是一个python样本列表。 它包含一个示例,它是您的功能列表。 但是,如果您有大量数值数据,则必须 ...