category stringclasses 107
values | title stringlengths 15 179 | question_link stringlengths 59 147 | question_body stringlengths 53 33.8k | answer_html stringlengths 0 28.8k | __index_level_0__ int64 0 1.58k |
|---|---|---|---|---|---|
implement regression | Parallel/multithreading version of linear regression in Julia | https://stackoverflow.com/questions/64470373/parallel-multithreading-version-of-linear-regression-in-julia | <p>I implemented regression model with interactions using Julia <code>GLM</code> package:</p>
<p><code>Reg = lm(@formula(dep_var ~ var1&var2&var3), data, true)</code>.</p>
<p>Fitting this formula requires a lot of RAM (> 80 GB), but I noticed that the calculations are performed on one core, although my OS (x... | <p>Fitting a regression model is basically doing lots of matrix operations. By default Julia is using BLAS and the easiest thing you can do is to try to configure it to be multi-threaded. This requires running Julia in a multi-threaded setting <em>and</em> setting the <code>BLAS.set_num_threads()</code> configuration.<... | 34 |
implement regression | Implementing logistic regression with L2 regularization in Matlab | https://stackoverflow.com/questions/9369379/implementing-logistic-regression-with-l2-regularization-in-matlab | <p>Matlab has built in logistic regression using mnrfit, however I need to implement a logistic regression with L2 regularization. I'm completely at a loss at how to proceed. I've found some good papers and website references with a bunch of equations, but not sure how to implement the gradient descent algorithm neede... | <p>Here is an annotated piece of code for plain gradient descent for logistic regression. To introduce regularisation, you will want to update the cost and gradient equations. In this code, theta are the parameters, X are the class predictors, y are the class-labels and alpha is the learning rate</p>
<p>I hope this he... | 35 |
implement regression | Implementing a linear regression using gradient descent | https://stackoverflow.com/questions/58996556/implementing-a-linear-regression-using-gradient-descent | <p>I'm trying to implement a linear regression with gradient descent as explained in this article (<a href="https://towardsdatascience.com/linear-regression-using-gradient-descent-97a6c8700931" rel="nofollow noreferrer">https://towardsdatascience.com/linear-regression-using-gradient-descent-97a6c8700931</a>).
I've foll... | <blockquote>
<p>Why would a formula work on one data set and not another one?</p>
</blockquote>
<p>In addition to sascha's remarks, here's another way to look at problems of this application of gradient descent: The algorithm offers no guarantee that an iteration yields a better result than the previous, so it doesn... | 36 |
implement regression | How to implement stratified sampling in randomForest regression in R? | https://stackoverflow.com/questions/49197422/how-to-implement-stratified-sampling-in-randomforest-regression-in-r | <p>How can I implement stratified sampling in a randomForest <strong>regression</strong> in R? I know that the strata and sampsize parameters are used in randomForest classification problems, but I get
Error in { : task 1 failed - "sampsize should be of length one."</p>
<p>My data:</p>
<pre><code>x <- sample(1:10... | 37 | |
implement regression | Implementing linear regression from scratch in python | https://stackoverflow.com/questions/74825378/implementing-linear-regression-from-scratch-in-python | <p>I'm trying to Implement linear regression in python using the following gradient decent formulas (Notice that these formulas are after partial derive)
<a href="https://i.sstatic.net/EQcjo.png" rel="nofollow noreferrer">slope</a>
<a href="https://i.sstatic.net/bhJsz.png" rel="nofollow noreferrer">y_intercept</a></p>
... | <p>One small problem you have is that you are returning the last values of w and b, when you should be returning the second-to-last parameters (because they yield a lower cost). This should not really matter that much... unless your learning rate is too high and you are immediately getting a higher value for the cost f... | 38 |
implement regression | Linear Regression - Implementing Feature Scaling | https://stackoverflow.com/questions/56364169/linear-regression-implementing-feature-scaling | <p>I was trying to implement Linear Regression in Octave 5.1.0 on a data set relating the GRE score to the probability of Admission.
The data set is of the sort,</p>
<blockquote>
<p>337 0.92 <br>
324 0.76 <br>
316 0.72 <br>
322 0.8 <br>
. <br> . <br> . <br></p>
</blockquote>
<p>My main Program.m file looks ... | <p>The easiest way to check whether your implementation is correct is to compare with a validated implementation of linear regression. I suggest using an alternative implementation approach like the one suggested <a href="https://www.lauradhamilton.com/tutorial-linear-regression-with-octave" rel="nofollow noreferrer">h... | 39 |
implement regression | Is there an implement of focal loss for regression problem? | https://stackoverflow.com/questions/70449172/is-there-an-implement-of-focal-loss-for-regression-problem | <p>Proposed in RetinaNet, Focal Loss is a efficient solution to class imbalance for classification problem. But data imbalance can also occur in regression problem. Is there any implementation of focal loss in regression problem?</p>
| 40 | |
implement regression | Logistic Regression Implementation | https://stackoverflow.com/questions/45705490/logistic-regression-implementation | <p>I am having some difficulties in implementing logistic regression, in terms of how should I should proceed stepwise. According to what I have done so far I am implementing it in the following way:</p>
<ul>
<li><p>First taking <code>theta</code> equal to the number of features and making it a <code>n*1</code> vector... | <p>You are computing the gradient in the last step, while it has been computed before in the computation of the new <code>theta</code>. Moreover, your definition of the cost function contains a regularization parameter, but this is not incorporated in the gradient computation. A working version without the regularizati... | 41 |
implement regression | How to implement polynomial logistic regression in scikit-learn? | https://stackoverflow.com/questions/55937244/how-to-implement-polynomial-logistic-regression-in-scikit-learn | <p>I'm trying to create a non-linear logistic regression, i.e. polynomial logistic regression using scikit-learn. But I couldn't find how I can define a degree of polynomial. Did anybody try it?
Thanks a lot!</p>
| <p>For this you will need to proceed in two steps. Let us assume you are using the iris dataset (so you have a reproducible example):</p>
<pre><code>from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.model_selecti... | 42 |
implement regression | Trying to implement Logistic Regression with stochastic gradient descent but gettin KEYError | https://stackoverflow.com/questions/65860488/trying-to-implement-logistic-regression-with-stochastic-gradient-descent-but-get | <p>I'am trying to implement logistic regression with sgd. My dataset is splited like <code>train_features.npy</code>, <code>train_labels.npy</code>, <code>test_features.npy</code>, <code>test_labels.npy</code>. My sgd function is here:</p>
<pre><code>def stoch_grd_dcnt(train, batch_size, n0, n1, max_epoch, delta):
... | 43 | |
implement regression | How to implement Softmax regression with pytorch? | https://stackoverflow.com/questions/64783744/how-to-implement-softmax-regression-with-pytorch | <p>I am working on a uni assignment where I need to implement <code>Softmax Regression</code> with <code>Pytorch</code>. The assignment says:</p>
<pre><code>Implement Softmax Regression as an nn.Module and pipe its output with its output with torch.nn.Softmax.
</code></pre>
<p>As I am new to pytorch, I am not sure how ... | <p>As far as I understand, the assignment wants you to implement your own version of the Softmax function. But, I didn't get what do you mean by <code>and pipe its output with torch.nn.Softmax</code>. Are they asking you to return the output of your custom Softmax along with <code>torch.nn.Softmax</code> from your cust... | 44 |
implement regression | How to implement Logistic regression with lasso or ridge? | https://stackoverflow.com/questions/60479134/how-to-implement-logistic-regression-with-lasso-or-ridge | <p>I have to implement a logistic regression and regularise with lasso or ridge and then calculate the RSS choosing the model that will shrinks up to 10 features or less.
I tried, using the package glmnet</p>
<pre><code>x <- Train_set %>% dplyr::select(-Diag) %>% as.matrix()
y <- Train_set$Diag %>% ... | 45 | |
implement regression | Multiple linear regression in Matlab R2014a | https://stackoverflow.com/questions/30751080/multiple-linear-regression-in-matlab-r2014a | <p>Is there any function that does this? I keep searching and the closest match is <strong>regression</strong>, but it's for the simple linear regression. In Matlab R2015a they have implemented <strong>regress</strong>, but I don't have that version.</p>
<p>Thanks.</p>
| <p>Both <code>fitlm</code> and <code>regress</code> do the same thing.</p>
| 46 |
implement regression | Is LASSO regression implemented in Statsmodels? | https://stackoverflow.com/questions/43446919/is-lasso-regression-implemented-in-statsmodels | <p>I would love to use a linear LASSO regression within statsmodels, so to be able to use the 'formula' notation for writing the model, that would save me quite some coding time when working with many categorical variables, and their interactions. However, it seems like it is not implemented yet in stats models?</p>
| <p>Lasso is indeed implemented in statsmodels. The documentation is given in the url below:</p>
<p><a href="http://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.fit_regularized.html" rel="noreferrer">http://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.fit_regula... | 47 |
implement regression | Neural Network for Regression using PyTorch | https://stackoverflow.com/questions/72874433/neural-network-for-regression-using-pytorch | <p>I am trying to implement a Neural Network for predicting the h1_hemoglobin in PyTorch. After creating a model, I kept 1 in the output layer as this is Regression. But I got the error as below. I'm not able to understand the mistake. Keeping a large value like 100 in the output layer removes the error but renders the... | <p>Your response variable h1_hemoglobin looks like continous response variable. If that's the case please change the Torch Tensor Type for <code>y_train</code> and <code>y_test</code> from <code>LongTensor</code> to <code>FloatTensor</code> or <code>DoubleTensor</code>.</p>
<p>According to the Pytorch docs, <code>Cross... | 48 |
implement regression | Problem implementing Partial Least Squares Regression | https://stackoverflow.com/questions/73818502/problem-implementing-partial-least-squares-regression | <p>I’m trying to implement the Partial Least Squares Regression model in R using the <code>pls</code> package. The following data frame represents my data, where I have two response variables and three explanatory variables.</p>
<pre><code>library(pls)
df <- data.frame(x1 = rnorm(20),
x2 = rnorm(20)... | 49 | |
implement regression | Implementing lasso regression using TensorFlow | https://stackoverflow.com/questions/39815728/implementing-lasso-regression-using-tensorflow | <p>I want to run Lasso regression using TensorFlow. As the Lasso regression is simply adding L1-norm to the cost, I am going to define my cost term as</p>
<pre><code>cost = RSS + tf.nn.l1_norm(Weight) or
cost = RSS + tf.reduce_sum(tf.abs(Weight))
train = tf.train.GradientDescentOptimizer(cost)
</code></pre>
<p>Is the... | 50 | |
implement regression | Implement a Regression/Classification Neural Network in Python | https://stackoverflow.com/questions/47626075/implement-a-regression-classification-neural-network-in-python | <h3>Problem Context</h3>
<p>I am trying to learn Neural Networks in Python, & I've developed an implementation of a Logistic Regression based NN.</p>
<p>Here is the code - </p>
<pre><code>import numpy as np
# Input array
X = np.array([[1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 0, 1]])
# Output
y = np.array([[1], [1], ... | <p>You should try to remove sigmoid function on your output.</p>
<p>As for linear regression, output range may be large, while output of sigmoid or tanh function is [0, 1] or [-1, 1], which makes minimize of error function not possible. </p>
<p>======= UPDATE ======</p>
<p>I try to accomplish it in tensorflow, the c... | 51 |
implement regression | Linear regression implementation in Octave | https://stackoverflow.com/questions/54104134/linear-regression-implementation-in-octave | <p>I recently tried implementing linear regression in octave and couldn't get past the online judge. Here's the code</p>
<pre><code>function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
for iter = 1:num_iters
for... | <p>You don't need the inner <code>for</code> loop. Instead you can use the <code>sum</code> function.</p>
<p>In code:</p>
<pre><code>for iter = 1:num_iters
j= 1:m;
temp1 = sum((theta(1) + theta(2) .* X(j,2)) - y(j));
temp2 = sum(((theta(1) + theta(2) .* X(j,2)) - y(j)) .* X(j,2));
theta(1) = theta... | 52 |
implement regression | Linear Regression\Gradient Descent python implementation | https://stackoverflow.com/questions/14993454/linear-regression-gradient-descent-python-implementation | <p>I'm trying to implement linear regression using the gradient descent method from scratch for learning purposes. One part of my code is really bugging me. For some reason the variable <code>x</code> is being altered after I run a line of code and I'm not sure why. </p>
<p>The variables are as follow. <code>x</code> ... | <p>What is happening is that python is computing the list <code>zip(x,y)</code>, then each iteration of your for loop is overwriting <code>(x,y)</code> with the corresponding element of <code>zip(x,y)</code>. When your for loop terminates <code>(x,y)</code> contains <code>zip(x,y)[-1]</code>.</p>
<p>Try </p>
<pre><c... | 53 |
implement regression | code for h2o ensemble implementation in r for regression in r | https://stackoverflow.com/questions/48490900/code-for-h2o-ensemble-implementation-in-r-for-regression-in-r | <p>I have searched for different portals and even in h2o ensemble documentation and all I have got ensemble examples for only classification problem binary in nature but not a single example showing how to implement general stacking or h2o ensembling for a simple regression problem in r </p>
<p>I request anyone to pl... | <p>Here's an example of building a stacked ensemble for a regression problem (predicting age) in R:</p>
<pre><code>library('h2o')
h2o.init()
files3 = "http://h2o-public-test-data.s3.amazonaws.com/smalldata/prostate/prostate.csv"
col_types <- c("Numeric","Numeric","Numeric","Enum","Enum","Numeric","Numeric","Numeri... | 54 |
implement regression | Understanding this implementation of logistic regression | https://stackoverflow.com/questions/41959431/understanding-this-implementation-of-logistic-regression | <p>Following this example implementation of Logistic Regression from scikit-learn :
<a href="https://analyticsdataexploration.com/logistic-regression-using-python/" rel="nofollow noreferrer">https://analyticsdataexploration.com/logistic-regression-using-python/</a></p>
<p>After running predict , the following is prod... | <p>As stated in the documentation the values returned by the <code>predict</code> function are class labels (like the values you provided to the <code>fit</code> function as y). In your case 1 for survived and 0 for not survived.</p>
<p>If you want the scores of each prediction you should use the <code>decision_functi... | 55 |
implement regression | Implementing softmax regression | https://stackoverflow.com/questions/39988084/implementing-softmax-regression | <p>I am trying to make a neural network using softmax regression. I am using the following regression formula:</p>
<p><a href="https://i.sstatic.net/oaAL7.png" rel="nofollow"><img src="https://i.sstatic.net/oaAL7.png" alt="enter image description here"></a></p>
<p>Lets say I have an input of 1000x100. In other words,... | <p>If you are training Neural Networks, it might we worth while to check <a href="http://deeplearning.net/tutorial/mlp.html" rel="nofollow">Theano</a> library. It features various output thresholding functions like <em>tanh</em>, <em>softmax</em>, etc. and allows training of neural networks on GPU.</p>
<p>Also x^n is ... | 56 |
implement regression | How to extract Regression predictor of Scikit-learn to implement into C++? | https://stackoverflow.com/questions/37802891/how-to-extract-regression-predictor-of-scikit-learn-to-implement-into-c | <p>I did some training using Random Forest Regression (or any kind of regressions) of Scikit-learn and got the predictor:</p>
<pre><code>predictor = RandomForestRegressor(n_estimators=n_estimators)
predictor.fit(X_train, Y_train)
</code></pre>
<p>How can I extract information in <code>predictor</code> to implement in... | <p>The <a href="http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html" rel="nofollow">sklearn documentation for RFR</a> says that you have</p>
<pre><code> property estimators_ : list of DecisionTreeRegressor
</code></pre>
<p>From <a href="http://scikit-learn.org/stable/modules/g... | 57 |
implement regression | Ridge Polynomial Regression: Direct implementation in python | https://stackoverflow.com/questions/66905960/ridge-polynomial-regression-direct-implementation-in-python | <p>I want to directly implement the ridge polynomial regression in python without using related libraries such as sklearn. The direct calculation is given by:</p>
<p>w = (XTX + lambda * I)^-1*XTy.</p>
<p>The code is as follows:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from openpyxl import load_... | <p>You may check this implementation made by me which uses the following formula: A^T * A * x = A^T * B</p>
<pre class="lang-py prettyprint-override"><code>import numpy as np
import matplotlib.pyplot as plt
DATA = np.array([(-5, 12), (-3, 2), (-2, -7), (-1, -4), (2, 3), (3, 1), (5, 4), (7, 9)])
n, m = DATA.shape
def... | 58 |
implement regression | How can I implement multivariate linear regression? | https://stackoverflow.com/questions/47357431/how-can-i-implement-multivariate-linear-regression | <p>I have built a simple linear regressor below...</p>
<pre><code>import numpy as np
x = np.array([[0.0], [0.33], [0.66], [1.0]])
y = np.array([[1.0, 2.0, 3.0, 4.0]]).T
w = np.random.random((1, 1))
for j in xrange(100000):
a2 = np.dot(x, w) + 1
w += x.T.dot((y - a2))
print(a2)
</code></pre>
<p>Now here is my... | <p>I think what you need is <strong>numpy concatenate</strong> function:</p>
<pre><code>import numpy as np
x = np.array([[0.0], [0.33], [0.66], [1.0]])
x2 = np.array([[0.0], [0.33], [0.66], [1.0]])
y = np.array([[1.0, 2.0, 3.0, 4.0]]).T
w = np.random.random((1, 2))
x_all = np.concatenate((x,x2),axis = 1)
for j in xr... | 59 |
implement regression | Implementing LSTM regression model with tensor flow | https://stackoverflow.com/questions/47277171/implementing-lstm-regression-model-with-tensor-flow | <p>I am trying to implement a tensor flow LSTM regression model for a list of inputs number.
example: </p>
<pre><code> input_data = [1, 2, 3, 4, 5]
time_steps = 2
-> X == [[1, 2], [2, 3], [3, 4]]
-> y == [3, 4, 5]
</code></pre>
<p>The code is below:</p>
<pre><code>TIMESTEPS = 20
num_hidden=20
Xd, y... | <p>As mentioned in the comment, you had to change your loss function to the MSE function and reduce your learning rate. Is your error converging to zero ?</p>
| 60 |
implement regression | Fast softmax regression implementation in tensorflow | https://stackoverflow.com/questions/39770254/fast-softmax-regression-implementation-in-tensorflow | <p>I am trying to implement the softmax regression model in tensorflow in order to make a benchmark with other mainstream deep-learning frameworks. The official documentation code is slow because of the <a href="https://github.com/tensorflow/tensorflow/issues/2919" rel="nofollow">feed_dict issue</a> in tensorflow. I am... | <p>Just as follows.</p>
<pre><code>from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
import numpy as np
batch_size = 32 #any size you want
mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)
x = tf.placeholder(tf.float32, shape = [None, 784])
y = tf.placeholder(tf.floa... | 61 |
implement regression | Parallel implementation of least angle regression | https://stackoverflow.com/questions/23264997/parallel-implementation-of-least-angle-regression | <p>I'm looking for the R package or script which the least angle regression or lasso implemented in parallel fashion.
Does anyone knows some?</p>
| <p>Yes. The <strong>Lars</strong> package in R will do this. Check out this package - <a href="http://cran.r-project.org/web/packages/lars/index.html" rel="nofollow">http://cran.r-project.org/web/packages/lars/index.html</a></p>
<p>And the R command would be </p>
<pre><code>lars(x, y, type = c("lasso"))
</code></pre>... | 62 |
implement regression | python linear regression implementation | https://stackoverflow.com/questions/39478437/python-linear-regression-implementation | <p>I've been trying to do my own implementation of a simple linear regression algorithm, but I'm having some trouble with the gradient descent.</p>
<p>Here's how I coded it:</p>
<pre><code>def gradientDescentVector(data, alpha, iterations):
a = 0.0
b = 0.0
X = data[:,0]
y = data[:,1]
m = data.shap... | <p>It is clear that the parameters are diverging from the optimum ones. One possible reason may be that you are using too large a value for the learning rate ("alpha"). Try decreasing the learning rate. Here is a rule of thumb. Start always from a small value like 0.001. Then try increasing the learning rate by taking ... | 63 |
implement regression | implementing keras version of quantile loss for regression | https://stackoverflow.com/questions/77529336/implementing-keras-version-of-quantile-loss-for-regression | <p>I am trying to implement Quantile loss for a regression problem based on the formula from this <a href="https://medium.com/@mlblogging.k/14-loss-functions-you-can-use-for-regression-b24db8dff987" rel="nofollow noreferrer">article</a> (number 14 at the end of the article):</p>
<p><a href="https://i.sstatic.net/cjJzO.... | 64 | |
implement regression | Fast way to implement a polynomial regression on each pandas dataframe row | https://stackoverflow.com/questions/76077118/fast-way-to-implement-a-polynomial-regression-on-each-pandas-dataframe-row | <p>I have the following pandas dataframe:</p>
<pre><code>df = pd.DataFrame({0: [11, 12, 31], 1: [6, 14, 27], 2: [11, 24, 21], 3: [1, 24, 20]})
0 1 2 3
0 11 6 11 1
1 12 14 24 24
2 31 27 21 20
</code></pre>
<p>For each row at the time, I want to implement a polynomial regression, where column nam... | <p><a href="https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html" rel="nofollow noreferrer"><code>polyfit</code></a> can take a 2d <code>y</code>-param of the same length with <code>x</code>, so:</p>
<pre><code>np.polyfit(df.columns, df.T, 2).T
</code></pre>
<p>gives:</p>
<pre><code>array([[-1.25, 1.25,... | 65 |
implement regression | I want to implement a tree-based regression model using rss | https://stackoverflow.com/questions/56337405/i-want-to-implement-a-tree-based-regression-model-using-rss | <p>1.2 RSS
As stated in chapter 8 of the textbook, we need a parameter to measure the efficiency of a specific split/tree. We choose here Residual Sum of Squares. Implement RSS calculation for the list of splits, knowing that the value to predict (Wage(k)) is contained in element[-1] for element in split.
You can use the ... | <p>If I understand correctly, you are only asking for the calculation marked #TODO in the code you posted. If you calculate the errors predicted by your model, these error values are sometimes called the "residual errors". You cannot simply sum these, some are negative and some are positive so they might cancel each ot... | 66 |
implement regression | parameters error in azure ML designer in evaluation metrics in regression model | https://stackoverflow.com/questions/73833320/parameters-error-in-azure-ml-designer-in-evaluation-metrics-in-regression-model | <p>I developed a designer to implement regression models in azure machine learning studio. I have taken the data set pill and then split the data set into train and test in prescribed manner. When I am trying to implement the evaluation metrics and run the pipeline, it was showing a warning and error in the moment I ca... | <p>Creating a sample pipeline with designer with mathematical format.</p>
<p><a href="https://i.sstatic.net/kCx3A.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kCx3A.png" alt="enter image description here" /></a></p>
<p>We need to create a compute instance.</p>
<p><a href="https://i.sstatic.net/7bQA5.p... | 67 |
implement regression | LinAlgError Singular Matrix when implementing logistic regression | https://stackoverflow.com/questions/64381015/linalgerror-singular-matrix-when-implementing-logistic-regression | <p>I am trying to implement a logistic regression model, but when I try to print the results I'm getting an error that I've looked up and tried to figure out how to solve, but haven't been able to.</p>
<p>Here's what that looks like:</p>
<pre><code>#Columns
columns = new_df[['DIABETES_NO','DIABETES_INSULIN', 'DIABETES_... | <p>It is quite clear that you do not understand how to handle categorical variables. You include a whole set of one-hot encoded dummies (e.g. including <code>SEX_male</code> and <code>SEX_female</code> together) per categorical variable, essentially introducing multiple constants to your regression, hence singular matr... | 68 |
implement regression | Implementing Linear Regression in ASP.NET web application | https://stackoverflow.com/questions/67072491/implementing-linear-regression-in-asp-net-web-application | <p>I was supposed to develop a web application that also includes predicting an expected arrival date of parcel value based on the origin location of the value, and I was thinking of using Linear Regression model. Though I'm not sure if this is feasible: implementing linear regression in web application. I can't seem t... | 69 | |
implement regression | TensorFlow Returning nan When Implementing Logistic Regression | https://stackoverflow.com/questions/38538635/tensorflow-returning-nan-when-implementing-logistic-regression | <p>I've been trying to implement Logistic Regression in TensorFlow following the MNIST example but with data from a CSV. Each row is one sample and has 12 dimensions. My code is the following:</p>
<pre><code>batch_size = 5
learning_rate = .001
x = tf.placeholder(tf.float32,[None,12])
y = tf.placeholder(tf.float32,[Non... | <p>The issue you are having is because log(pred) is not defined for pred = 0. The "hacky" way around this is to use <code>tf.maximum(pred, 1e-15)</code> or <code>tf.clip_by_value(pred, 1e-15, 1.0)</code>.</p>
<p>An even better solution, however, is using <code>tf.nn.softmax_cross_entropy_with_logits(pred)</code> inste... | 70 |
implement regression | Implementing Logistic Regression in Theano with Climin | https://stackoverflow.com/questions/36742032/implementing-logistic-regression-in-theano-with-climin | <p>I want to implement logistic regression with minibatches on MNIST using Theano. I want to try out different optimisers, so I decided to use a library called <a href="https://github.com/BRML/climin" rel="nofollow">climin</a>. Climin offers several functions, which receive the parameters of the model, loss and / or th... | <p>Your code passes a compiled function (instead of a Theano expression) to <code>T.grad</code>. Replace <code>loss</code> with <code>NLL</code> and you should be fine</p>
<pre><code>g_W = theano.function(inputs = [ x, y ], outputs = T.grad(cost=NLL, wrt=W))
g_b = theano.function(inputs = [ x, y ], outputs = T.grad(c... | 71 |
implement regression | Verifying Linear Regression implementation using python | https://stackoverflow.com/questions/41312507/verifying-linear-regression-implementation-using-python | <p>I just started with machine learning, spent few hours learning Linear Regression. Based on my understanding I implemented it from scratch in python (code below) without regularisation. Is my logic correct or does it need any improvements?</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
# Assigni... | <p>To check your model, a simple thing to do would be to <em>split your data into a training set and a test set</em>. The training set is used to <em>fit the model</em>, by being passed as an argument to the <code>linReg</code> function, and the features of the test set are used for <em>prediction</em> (with your so-ca... | 72 |
implement regression | MATLAB implementation for Flexible Least Squares (FLS) regression | https://stackoverflow.com/questions/11474052/matlab-implementation-for-flexible-least-squares-fls-regression | <p>Is there a MATLAB implementation for <a href="http://www2.econ.iastate.edu/tesfatsi/flshome.htm" rel="nofollow">Flexible Least Squares (FLS) regression</a><sup>1</sup>?</p>
<p>I am looking for a decent (well, the least painful) way to handle regression with time-varying coefficients. All ideas are welcome, but the ... | <p>I've found a <a href="https://github.com/bwlewis/fls/blob/master/R/fls.R" rel="nofollow">R code on GitHub</a> of the FLS regression. I have converted it to MATLAB, but it may have some errors due to differences between the functions of R and MATLAB. Now, we just need to test it in order to do the final adjustments.<... | 73 |
implement regression | Failing to implement logistic regression using 'equinox' and 'optax' library | https://stackoverflow.com/questions/76146548/failing-to-implement-logistic-regression-using-equinox-and-optax-library | <p>I am trying to implement logistic regression using equinox and optax libraries, with the support of JAX. While training the model, the loss is not decreasing over time,and model is not learning. Herewith attaching a reproducible code with toy dataset for reference:</p>
<pre><code>import jax
import jax.nn as jnn
impo... | <p>The first time you print your loss is after 1000 epochs. If you change it to print the loss of the first 10 epochs, you see that the optimizer is rapidly converging:</p>
<pre class="lang-py prettyprint-override"><code> # ...
if epoch < 10 or (epoch + 1)%1000 ==0:
print(f"loss at epoch {epoch+1... | 74 |
implement regression | Linear Regression with Multiple Variables - Python - Implementation issues | https://stackoverflow.com/questions/8971034/linear-regression-with-multiple-variables-python-implementation-issues | <p>I am trying to implement Linear Regression with Multiple variables( actually , just 2 ) . I am using the data from the ML-Class Stanford. I got it working correctly for the single variable case. The same code <em>should</em> have worked for multiple, but , does not. </p>
<p>LINK to the data : </p>
<p><a href="http... | <p>The global variables and quadruply nested loops worry me. That and reading and writing the data to files multiple times.</p>
<p>Is your data so big it doesn't easily fit in memory?</p>
<p>Why not use the <a href="https://docs.python.org/3/library/csv.html" rel="nofollow noreferrer">csv</a> module for the file proces... | 75 |
implement regression | Error while implementing Multi-Linear regression Using pytorch | https://stackoverflow.com/questions/75918642/error-while-implementing-multi-linear-regression-using-pytorch | <p>I am trying to implement 1 variable Linear regression using PyTorch. However i get [NaN] as output of my prediction when i train my model using large integer inputs .</p>
<pre><code>import torch
from torch.autograd import Variable
import numpy as np
class linearRegression(torch.nn.Module):
# in... | <p>The gradients are getting too large. You could normalize the data or reduce the learning rate.</p>
| 76 |
implement regression | Why is my implementation of linear regression not working? | https://stackoverflow.com/questions/77569740/why-is-my-implementation-of-linear-regression-not-working | <p>I am trying to implement linear regression from scratch in python.</p>
<p>For reference, here are the mathematical formulae I have used: <a href="https://i.sstatic.net/7zzc1.png" rel="nofollow noreferrer">Equations</a></p>
<p>This is what I tried:</p>
<pre class="lang-py prettyprint-override"><code>class LinearRegre... | <p>It is overflowing because you use to large numbers in your example. Try using:</p>
<pre><code>regr = LinearRegression(features=np.linspace(0, 1000, 200, dtype=np.float64).reshape((20, 10))/1000, targets=np.linspace(0, 200, 20, dtype=np.float64)/1000)
regr.gradientDescent(0.1, 1e-3, 1e+3)
regr.cost_function()
</code>... | 77 |
implement regression | How to implement Rolling Regression in Python | https://stackoverflow.com/questions/74322560/how-to-implement-rolling-regression-in-python | <p>I'm trying to predict the Adjusted Closing Price for the next day for a stock using Rolling Regression.</p>
<pre><code> Open High Low Close Adj Close
0 26.629999 27.000000 26.290001 26.600000 26.599386
1 26.670000 27.450001 26.540001 27.350000 27.349369
2 ... | <p>You could transform your window into separate columns, like so:</p>
<pre class="lang-py prettyprint-override"><code>
# == Necessary Imports ====================================
# Note: to install ``sklearn`` run: ``pip install scikit-learn``
import pandas as pd
from sklearn.pipeline import Pipeline
from sklearn.imp... | 78 |
implement regression | How to implement multi-branch regression trees in R | https://stackoverflow.com/questions/17294632/how-to-implement-multi-branch-regression-trees-in-r | <p>Is it possible to do the multi branch regression trees(non binary split) using R?</p>
| <p>A word on binary trees, contesting superiority of non-binary: <a href="http://bus.utk.edu/stat/datamining/Tree%20Structured%20Data%20Analysis%20%28SPSS%29.pdf" rel="nofollow">here</a></p>
<p>Tree models in R: <a href="http://plantecology.syr.edu/fridley/bio793/cart.html" rel="nofollow">here</a></p>
<p>R Party pack... | 79 |
implement regression | Classification and regression trees implementation in java | https://stackoverflow.com/questions/9708269/classification-and-regression-trees-implementation-in-java | <p>Are there any libs implementing classification and regression trees in java? Something very close to Matlab's classregtree command required.</p>
| <p>Try <a href="http://www.cs.waikato.ac.nz/ml/weka/" rel="nofollow">Weka</a></p>
| 80 |
implement regression | How can I implement a linear regression line in a Vizframe Chart? | https://stackoverflow.com/questions/42939004/how-can-i-implement-a-linear-regression-line-in-a-vizframe-chart | <p>I have a scatter plot Vizframe chart in which I need to include a linear regression/trend line. Any idea how this can be done? It appears this is not something offered by vizframe 'out of box'? I can't find a solution for this! </p>
<p><strong>Question:</strong></p>
<p>Any suggestions on a feasible way to implemen... | <p>Unfortunately, you have some limitations inherent to the viz charts. Namely:</p>
<ul>
<li>You cannot add "oblique" reference lines (= the trend line) to the chart. You can only add vertical / horizontal ones via the <a href="https://sapui5.hana.ondemand.com/sdk/explored.html#/sample/sap.viz.sample.ReferenceLine/pre... | 81 |
implement regression | Implementations of local regression and local likelihood methods | https://stackoverflow.com/questions/14411627/implementations-of-local-regression-and-local-likelihood-methods | <p>I am looking for an efficient implementation of local regression (LOESS) and local likelihood methods such as local logistic regression (local likelihood methods are discussed, for example, in section 6.5 of <a href="http://www-stat.stanford.edu/%7Etibs/ElemStatLearn/" rel="nofollow noreferrer">Elements of Statistic... | <p>In R there are the 'locfit' and 'mgcv' packages that I would suggest do forms of local regression. I believe the locfit package is simply a syntactic bridge to an underlying C package. (But not C++.)</p>
| 82 |
implement regression | ValueError: Unknown label type: continuous. When implementing regression | https://stackoverflow.com/questions/74815755/valueerror-unknown-label-type-continuous-when-implementing-regression | <p>I am trying to predict the price of taxi fares using a neural network, I managed to run it for one optimizer and for a given number of epochs, but when implementing gridSearchCV() to try out different optimizers and different amounts of epochs it outputs an error: [ValueError: Unknown label type: continuous.]</p>
<p... | <p>You mention wanting to implement a regression task. But the wrapper you are using is the <code>KerasClassifier</code> for classification. This is not meant for regression with continuous target. Hence the error message for classifiers</p>
<pre><code>ValueError: Unknown label type: continuous
</code></pre>
<p>Use the... | 83 |
implement regression | Python, GD and SGD implementation on Linear Regression | https://stackoverflow.com/questions/48843721/python-gd-and-sgd-implementation-on-linear-regression | <p>I try to understand and implement these algorithms in a simple example of linear regression. It is clear to me that the full batch gradient descent uses all the data to calculate the gradient and that the stochastic gradient descent uses only one.</p>
<p>Full Batch Gradient Descent:</p>
<pre><code>import pandas as... | <p>It seems like you set <code>alpha</code> in <code>SGDClassifier</code> to learning rate. <code>alpha</code> is not the learning rate.</p>
<p>To set constant learning rate set <code>SGDClassifier's</code> <code>learing_rate</code> to <code>constant</code> and <code>eta0</code> to your learning rate. </p>
<p>You'd a... | 84 |
implement regression | Implementation of Logistic regression | https://stackoverflow.com/questions/49818519/implementation-of-logistic-regression | <p>In the beginning, I am Japanese and not good at English, so my sentence may be incorrect. Sorry.
I made the code that is about logistic regression.
And I tested this code with dataset, but it is not appropriate rate.
That's why there is any mistakes in this code. If so, please let me know.
Moreover, I want to know t... | <p>I modified your code a little bit. The fitting is now solved in two ways: as a simple gradient descent and by means of the scipy optimizer. The gradient descent is very slow and should not be used for real problems. I tested the class on the data taken from the Machine Learning course at <a href="https://www.courser... | 85 |
implement regression | Implementing Polynomial Regression in Python (error:could not convert) | https://stackoverflow.com/questions/57076184/implementing-polynomial-regression-in-python-errorcould-not-convert | <h1>Hello world,</h1>
<h1>Problem</h1>
<p>Currently, trying to predict the margin (in percent) from a dataframe with 48098 rows and 70 features (all types). After that, the get dummies has been done in order to have only numerical values, which give the following shape (Shape Df is: (48098, 572)). </p>
<p>However, s... | 86 | |
implement regression | Numpy implementation for regression using NN | https://stackoverflow.com/questions/63093127/numpy-implementation-for-regression-using-nn | <p>I am implementing my own Neural Network model for regression using only <code>NumPy</code>, and I'm getting really weird results when I'm testing my model on m > 1 samples (for m=1 it works fine).. It seems like the model collapses and predicts only specific values for the whole batch:</p>
<pre><code>Input:
X [[ ... | <p>There wasn't a problem with my implementation, just overfitting.
<a href="https://www.researchgate.net/post/Neural_network_outputting_average_values_of_all_outputs-Am_I_doing_anything_wrong" rel="nofollow noreferrer">More information can be found here.</a></p>
| 87 |
implement regression | Where can I find data pairs to practice implementing linear regression? | https://stackoverflow.com/questions/35397525/where-can-i-find-data-pairs-to-practice-implementing-linear-regression | <p>I've recently started learning machine learning algorithms. I've written a program in python from scratch to implement linear regression but I need some data pairs to use.</p>
| <p>There are many dataset at internet to use, </p>
<p>have a look here, you can find many real datasets: <a href="https://archive.ics.uci.edu/ml/datasets.html" rel="nofollow">uci</a></p>
| 88 |
implement regression | How do I implement multiple linear regression in Python? | https://stackoverflow.com/questions/48257144/how-do-i-implement-multiple-linear-regression-in-python | <p>I am trying to write a multiple linear regression model from scratch to predict the key factors contributing to number of views of a song on Facebook. About each song we collect this information, i.e. variables I'm using:</p>
<pre><code>df.dtypes
clicked int64
listened_5s int64... | <p>I would suggest using regularisation with the Lasso, which also performs feature selection:</p>
<pre><code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LassoCV
from sklearn.preprocessing import StandardScaler
# Standardize the data (excluding 'views' which is the target vari... | 89 |
implement regression | How to implement Statsmodels Multinomial Logistic Regression (MNLogit) wald_test()? | https://stackoverflow.com/questions/63272453/how-to-implement-statsmodels-multinomial-logistic-regression-mnlogit-wald-test | <p>I'm (a Python newbie) writing Python code to mimic outputs in SAS and want to run a multinomial logistic regression on the SAS Wallet data set. I've done normal logistic regression previously on other data using statsmodels.Logit, but now am using statsmodels.MNLogit. According to the API (<a href="https://www.stats... | 90 | |
implement regression | How to fix nan values coming from the implementation of Logistic Regression? | https://stackoverflow.com/questions/62818741/how-to-fix-nan-values-coming-from-the-implementation-of-logistic-regression | <p>After I get some processes to get x_train and y_train, I flatten them. The code snippets are shown below.</p>
<p><strong>The flatten code</strong></p>
<pre><code>x_train = x_train_flatten.T
x_test = x_test_flatten.T
y_test = Y_test.T
y_train = Y_train.T
print("x train: ",x_train.shape)
print("x test: ... | <p>Here is my solution</p>
<ul>
<li>Apply feature scaling to x_train before training the model to stop producing nan values</li>
</ul>
<p>I write this code block before calling <code>logistic_regression method</code>.</p>
<pre><code>from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
x_train = sc_X... | 91 |
implement regression | R implementation of group lasso-regularized linear regression | https://stackoverflow.com/questions/10983629/r-implementation-of-group-lasso-regularized-linear-regression | <p>Does anyone know of any good implementation of group-lasso regularized linear regression in R (or even Matlab)?</p>
| <p>Have you looked at <strong><a href="http://www.gnu.org/software/octave/" rel="nofollow">GNU Octave</a></strong>? It does its work on command line so you can use it with any language that can read/write to file and execute shell commands to kick it off from within the program.</p>
<p>GNU Octave is featured in the <... | 92 |
implement regression | Select smoothing parameter and implement non-parametric regression in Python | https://stackoverflow.com/questions/60828059/select-smoothing-parameter-and-implement-non-parametric-regression-in-python | <p>I'm working in R to estimate non-parametric regression. The complete project: <a href="https://systematicinvestor.wordpress.com/2012/05/22/classical-technical-patterns" rel="nofollow noreferrer">https://systematicinvestor.wordpress.com/2012/05/22/classical-technical-patterns</a></p>
<p>My <code>R</code> code is the... | 93 | |
implement regression | Implement Ridge Regression Equation for a Neural Network | https://stackoverflow.com/questions/78597100/implement-ridge-regression-equation-for-a-neural-network | <p>I am trying to replicate the following equation in MATLAB to find the optimal output weight matrix of a neural network from training using ridge regression.</p>
<p><strong>Output Weight Matrix of a Neural Network after Training using Ridge Regression:</strong>
<a href="https://i.sstatic.net/O9byd971.png" rel="nofoll... | 94 | |
implement regression | Implementing Linear Regression using Gradient Descent | https://stackoverflow.com/questions/49081195/implementing-linear-regression-using-gradient-descent | <p>I have just started in machine learning and currently taking the course by andrew Ng's Machine learning Course. I have implemented the linear regression algorithm in python but the result is not desirable. I code of python is as follows:</p>
<pre><code>import numpy as np
x = [[1,1,1,1,1,1,1,1,1,1],[10,20,30,40,50,... | <p>Ah. I did this assignment too a while ago.</p>
<p>See this mentioned in Page 7 of the assignment PDF:</p>
<blockquote>
<p>Octave/MATLAB array indices start from one, not zero. If you’re
storing θ0 and θ1 in a vector called theta, the values will be
theta(1) and theta(2).</p>
</blockquote>
<p>So, in your whi... | 95 |
implement regression | Can I implement sample weights in statsmodels quantile regression? | https://stackoverflow.com/questions/41991585/can-i-implement-sample-weights-in-statsmodels-quantile-regression | <p>I have just learned about the statsmodels module by searching about quantile regression. I was wondering if there is a way to use statsmodels for quantile regressoin and take the errorbars of the data into account,
like in sklearn.linear_model.LinearRegression?</p>
<p><a href="http://scikit-learn.org/stable/module... | 96 | |
implement regression | Octave/Matlab implementation of confidence intervals in multiple regression | https://stackoverflow.com/questions/46752817/octave-matlab-implementation-of-confidence-intervals-in-multiple-regression | <p>I need to implement the confidence intervals of multiple regression coefficients in Octave/Matlab.</p>
<p>The task is defined in a common manner: data Y, design matrix X, coefficients β so that Y=βX. The code for β is then simply:</p>
<pre><code>beta = pinv(X)*Y
</code></pre>
<p>Now, as a stupid physicist, I am a... | <p>I think this is what you want to find:</p>
<pre><code>[b, bint, r, rint, stats] = regress (y, X, [alpha]).
</code></pre>
<p>where bint is the confidence interval for beta.</p>
<p>For details, please refer to <a href="https://octave.sourceforge.io/statistics/function/regress.html" rel="nofollow noreferrer">https:/... | 97 |
implement regression | Asking review and help for implementing logistic regression model | https://stackoverflow.com/questions/55664603/asking-review-and-help-for-implementing-logistic-regression-model | <p>I'm trying to implement a simple logistic regression model in Scala. That is there is only one independent variable to the dependent binary variable.
If we look as the example from Wikipedia: <a href="https://en.wikipedia.org/wiki/Logistic_regression" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Logistic_... | 98 | |
implement regression | How to implement Vector Auto-Regression in Python? | https://stackoverflow.com/questions/18348720/how-to-implement-vector-auto-regression-in-python | <p>I want to implement <strong>vector autoregression</strong> in python. My data is saved as a list of 3 lists. I found this -
<a href="http://statsmodels.sourceforge.net/stable/vector_ar.html#var" rel="nofollow noreferrer">http://statsmodels.sourceforge.net/stable/vector_ar.html#var</a>, but could not figure out the ... | <p>Changing the list of lists to a column stack (<a href="https://stackoverflow.com/questions/18348720/how-to-implement-vector-auto-regression-in-python#comment26955958_18348720">as @Josef suggests</a>) may solve your problem. For that, one might use <a href="https://numpy.org/doc/stable/reference/generated/numpy.colum... | 99 |
implement classification | Implementing Classification with Multi-Tenancy | https://stackoverflow.com/questions/78382174/implementing-classification-with-multi-tenancy | <p>Is it currently possible to utilize the classification endpoint alongside multi-tenancy in the latest version? I couldn't find any documentation regarding this feature. it's not implemented yet in v4.</p>
<p>As a workaround, I understand that using v3 is necessary. However, even with v3, there doesn't appear to be a... | <p>Duda from Weaviate here.</p>
<p>Right now, the classification feature is not implemented for a multi tenant collection.</p>
<p>Please, feel free to open a feature request in our Github repository here:
<a href="https://github.com/weaviate/weaviate/issues" rel="nofollow noreferrer">https://github.com/weaviate/weaviat... | 100 |
implement classification | Classification and regression trees implementation in java | https://stackoverflow.com/questions/9708269/classification-and-regression-trees-implementation-in-java | <p>Are there any libs implementing classification and regression trees in java? Something very close to Matlab's classregtree command required.</p>
| <p>Try <a href="http://www.cs.waikato.ac.nz/ml/weka/" rel="nofollow">Weka</a></p>
| 101 |
implement classification | Implement multiple classification in Java | https://stackoverflow.com/questions/25873645/implement-multiple-classification-in-java | <p>Is there a way to implement multiple classification in Java? For instance, take this UML diagram -
<img src="https://i.sstatic.net/Izpgx.png" alt="enter image description here"></p>
<p>How should the <code>GrainCrop</code> class be implemented?</p>
| <p>Java does not support multiple inheritance on classes, only interfaces can inherit from multiple interfaces. So what I would do is that the Class <code>GrainCrop</code> in question implements the interface from the two other classes. Then <code>GrainCrop</code> aggregates the two other classes and delegates to the "... | 102 |
implement classification | classification tree implementation in mathematica | https://stackoverflow.com/questions/6563407/classification-tree-implementation-in-mathematica | <p>I want to implement simple classification tree (binary classification) using <em>Mathematica.</em></p>
<p>How can I implement a binary tree in <em>Mathematica</em>? Is there is a symbol for doing that?</p>
| <p>Among the new objects in MMA 8 are <a href="http://reference.wolfram.com/mathematica/ref/TreeGraph.html" rel="nofollow noreferrer">TreeGraph</a>, <a href="http://reference.wolfram.com/mathematica/ref/CompleteKaryTree.html?q=CompleteKaryTree&lang=en" rel="nofollow noreferrer">CompleteKaryTree</a>, and <a href="ht... | 103 |
implement classification | Implementing classification tree with lists and vectors | https://stackoverflow.com/questions/46255195/implementing-classification-tree-with-lists-and-vectors | <p>So, I'm playing around with R in order to get the hang of Classification Trees. I'm primarily interested in making a abstract data type for the the Classification Tree so I can start building it. But unlike, C, Java, etc I can't have pointers to other nodes. I'm limited to lists and vectors. </p>
<p>How can I build... | <p>By playing a little bit with <code>data.tree</code> in R, I constructed this</p>
<pre><code>library(data.tree)
my.tree <- Node$new('my tree')
my.tree$key <- 1
my.tree$var.name <- 'blahblah'
function <- insert.Node(tree=NULL, key=1, var.name='abcd'){
if (is.null(tree$key)){
# Creation of ro... | 104 |
implement classification | gpflow classification implementation | https://stackoverflow.com/questions/68419128/gpflow-classification-implementation | <p>I want to implement a binary classification model using Gaussian process. According to the <a href="https://gpflow.readthedocs.io/en/master/notebooks/basics/classification.html" rel="nofollow noreferrer">official documentation</a>, I had the code as below.</p>
<p>The X has 2048 features and Y is either 0 or 1. After... | <p>I finally figured it out. The reason is the Y for VGP model should have a shape like (n_training_samples, 1) instead of (n_training_samples,).</p>
| 105 |
implement classification | How to implement hierarchical Transformer for document classification in Keras? | https://stackoverflow.com/questions/70271797/how-to-implement-hierarchical-transformer-for-document-classification-in-keras | <p>Hierarchical attention mechanism for document classification has been presented by Yang et al.
<a href="https://www.cs.cmu.edu/%7E./hovy/papers/16HLT-hierarchical-attention-networks.pdf" rel="nofollow noreferrer">https://www.cs.cmu.edu/~./hovy/papers/16HLT-hierarchical-attention-networks.pdf</a></p>
<p>Its implement... | <p>The implementation is recursive in the sense that you treat the average of your outputs of transformer <em>x</em> as the input to transformer <em>x+1</em>.</p>
<p>So let's say your data is structured as (batch, chapter, paragraph, sentence, token).</p>
<p>After the first transformation you end up with (batch, chapte... | 106 |
implement classification | Implement multi class classification using SVM in R | https://stackoverflow.com/questions/27125381/implement-multi-class-classification-using-svm-in-r | <p>I am trying to implement Multi class classification using SVM under e1071 package in R language. I read in a similar thread that SVM handles one vs one classifier by itself in the back end. Is it true.</p>
<p>Also, if I want to execute One vs Rest classifier, how to do it. And, while printing the summary of SVM m... | <p>Found the answer to my query above. I implemented one vs rest classifier by building binary classifiers on iris data present by default in R. It has 3 classes. So, I built 3 binary classifiers. Below is the code:</p>
<pre><code>data(iris)
head(iris)
table(iris$Species)
nrow(iris)
index_iris<-sample.split(iris$Sp... | 107 |
implement classification | How do I implement multilabel classification neural network with keras | https://stackoverflow.com/questions/54726518/how-do-i-implement-multilabel-classification-neural-network-with-keras | <p>I am attempting to implement a neural network using Keras with a problem that involves multilabel classification. I understand that one way to tackle the problem is to transform it to several binary classification problems. I have implemented one of these, but am not sure how to proceed with the others, mostly how d... | <p>The approach you are referring to is the <a href="https://scikit-learn.org/stable/modules/multiclass.html#one-vs-one" rel="nofollow noreferrer">one-versus-all</a> or the <a href="https://scikit-learn.org/stable/modules/multiclass.html#ovr-classification" rel="nofollow noreferrer">one-versus-one</a> strategy for mult... | 108 |
implement classification | How to implement a sequence classification LSTM network in CNTK? | https://stackoverflow.com/questions/38614265/how-to-implement-a-sequence-classification-lstm-network-in-cntk | <p>I'm working on implementation of LSTM Neural Network for sequence classification. I want to design a network with the following parameters:</p>
<ol>
<li><strong>Input :</strong> a sequence of <code>n</code> one-hot-vectors.</li>
<li><strong>Network topology :</strong> two-layer LSTM network.</li>
<li><strong>Output... |
<p>There is a <a href="https://github.com/Microsoft/CNTK/blob/4080c0a5afb4d80ac16de049f7e9cb234527ae29/Examples/SequenceClassification/SimpleExample/Python/SequenceClassification.py" rel="nofollow noreferrer">sequence classification example</a> that follows exactly what you're looking for.</p>
<p>The only difference... | 109 |
implement classification | How to implement class weight sampling in multi label classification? | https://stackoverflow.com/questions/78559061/how-to-implement-class-weight-sampling-in-multi-label-classification | <p>I am working on a multi label classification problem and need some guidance on computing class weights using Scikit-Learn.</p>
<p><strong>Problem Context:</strong></p>
<p>I have a dataset with 9973 training samples.The labels are one-hot encoded, representing 13 different classes.The shape of my training labels is (... | <p>You need to call <code>compute_class_weights</code> with keyword arguments rather than positional, just like they do in the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.utils.class_weight.compute_class_weight.html" rel="nofollow noreferrer">documentation</a>:</p>
<pre><code>compute_class_weight... | 110 |
implement classification | Confusion on cs231n image classification implementation | https://stackoverflow.com/questions/35691805/confusion-on-cs231n-image-classification-implementation | <p>I am recently taking CS231n online class. Trying to implement simple image classification code using CIFAR-10 dataset, in <a href="http://cs231n.github.io/classification/" rel="nofollow">http://cs231n.github.io/classification/</a></p>
<p>While running this code, on predict function, time takes too long, and even di... | 111 | |
implement classification | implement Naive Bayes Gaussian classifier on the number classification data | https://stackoverflow.com/questions/46513538/implement-naive-bayes-gaussian-classifier-on-the-number-classification-data | <p>I am trying to implement Naive Bayes Gaussian classifier on the number classification data. Where each feature represents a pixel. </p>
<p>When trying to implement this, I hit a bump, I've noticed that some the feature variance equate to 0.
This is an issue because I would not be able to divide by 0 when trying t... | <p>Very short answer is <strong>you cannot</strong> - even though you can usually try to fit Gaussian distribution to any data (no matter its true distribution) there is one exception - the constant case (0 variance). So what can you do? There are three main solutions:</p>
<ol>
<li><p>Ignore 0-variance pixels. I do no... | 112 |
implement classification | Multi-label classification implementation | https://stackoverflow.com/questions/63666851/multi-label-classification-implementation | <p>So far I have used Keras Tensorflow to model image processing, NLP, time series prediction. Usually in case of having labels with multiple entries, so multiple categories the task was always to just predict to which class the sample belongs. So for example the list of possible classes was [car, human, airplane, flow... | <p>The loss function to be used is indeed the <code>binary_crossentropy</code> with a <code>sigmoid</code> activation.</p>
<p>The <code>categorical_crossentropy</code> is not suitable for multi-label problems, because in case of the multi-label problems, the labels are not mutually exclusive. Repeat the last sentence: ... | 113 |
implement classification | classification and clustering of tweets | https://stackoverflow.com/questions/71296865/classification-and-clustering-of-tweets | <p>I am trying to implement classification and clustering of tweets and also using jupyter notebook and getting error while running this:</p>
<pre><code>nlp = en_core_web_sm.load()
tokenizer = RegexpTokenizer(r'\w+')
lemmatizer = WordNetLemmatizer()
stop = set(stopwords.words('english'))
punctuation = list(string.punct... | 114 | |
implement classification | How to implement class or sample weight sampling in multi label classification? | https://stackoverflow.com/questions/78595351/how-to-implement-class-or-sample-weight-sampling-in-multi-label-classification | <p>I'm currently working on a multi-label image classification problem where my dataset is significantly imbalanced. Each image in my dataset can have multiple labels. The labels are provided in a one-hot encoded format.
For example: [1,0,0,0,0,1,0] etc.</p>
<p>My train df:</p>
<pre><code>Image Index Finding Labels
0 ... | 115 | |
implement classification | How to implement Random Decision Forest classification in iOS | https://stackoverflow.com/questions/34871592/how-to-implement-random-decision-forest-classification-in-ios | <p>I am making an iOS application using objective-c and Xcode that will collect and analyze some data from the user. Using this data, it will return one of 3 classifications. I can use training data in either R or Python to create a random forest model that has the capability to do this. I would like to know now I can ... | <p>One approach is using <a href="http://bigml.com" rel="nofollow">BigML</a>, a cloud-based ML service that also provides a <a href="https://bigml.com/developers/" rel="nofollow">REST API</a> plus <a href="https://github.com/bigmlcom/bigml-swift" rel="nofollow">Swift</a> and <a href="https://github.com/bigmlcom/ml4ios"... | 116 |
implement classification | Is it possible to implement data classification scheme (for choropleth plot) in altair? | https://stackoverflow.com/questions/72021194/is-it-possible-to-implement-data-classification-scheme-for-choropleth-plot-in | <p>I am creating a choropleth plot function with Altair and want to use different data <a href="https://gisgeography.com/choropleth-maps-data-classification/" rel="nofollow noreferrer">classification scheme</a> for the size of the scatter markers. I have looked up the <code>bin parameters</code> and <code>bin transform... | 117 | |
implement classification | How to implement One-Vs-Rest for Multi-Class Classification in Julia? | https://stackoverflow.com/questions/74932178/how-to-implement-one-vs-rest-for-multi-class-classification-in-julia | <p>I’m new to Julia and i am trying to implement One-Vs-Rest Multi-Class Classification, and I was wondering if anyone could help me out. Here is a snippet of my code so far:
My data frame is basic since I’m trying to figure out the implementation first, my c column is my class consisting of [0, 1, 2], and my y, x1, x2... | <p>Here is how you can do the same manually using GLM.jl (there is a lot of boilerplate code, but I wanted to keep the example simple):</p>
<pre><code>df = DataFrame(x1=rand(100), x2=rand(100), x3=rand(100), target=rand([0, 1, 2], 100));
model0 = glm(@formula((target==0)~x1+x2+x3), df, Binomial(), ProbitLink())
model1 ... | 118 |
implement classification | Implementing attention in Keras classification | https://stackoverflow.com/questions/57059382/implementing-attention-in-keras-classification | <p>I would like to implement attention to a trained image classification CNN model. For example, there are 30 classes and with the Keras CNN, I obtain for each image the predicted class. However, to visualize the important features/locations of the predicted result. I want to add a Soft Attention after the FC layer. I ... | 119 | |
implement classification | Implementing Hierarchical Attention for Classification | https://stackoverflow.com/questions/49057752/implementing-hierarchical-attention-for-classification | <p>I am trying to implement the Hierarchical Attention <a href="https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf" rel="nofollow noreferrer">paper</a> for text classification. One of the challenges that I am finding is how to manage batching and updates to the weights of the network by the optimizer. The architecture of ... | 120 | |
implement classification | How to implement Image Classification and feature extraction using Matlab? | https://stackoverflow.com/questions/36307467/how-to-implement-image-classification-and-feature-extraction-using-matlab | <p>I'm currently performing a research that involves identification of food items using image classification techniques, I'm well versed in the theories and maths of SVM, yet I'm completely lost when it comes to implementing it using Matlab.</p>
<p>I would like some guiding steps to perform full image classification o... | 121 | |
implement classification | What FFT descriptors should be used as feature to implement classification or clustering algorithm? | https://stackoverflow.com/questions/27546476/what-fft-descriptors-should-be-used-as-feature-to-implement-classification-or-cl | I have some geographical trajectories sampled to analyze, and I calculated the histogram of data in spatial and temporal dimension, which yielded a time domain based feature for each spatial element. I want to perform a discrete <code>FFT</code> to transform the time domain based feature into frequency domain based fea... | <p>Generally you should extract just a small number of "Features" out of the complete FFT spectrum.</p>
<p>First: Use the log power spec.
Complex numbers and Phase are useless in these circumstances, because they depend on where you start/stop your data acquisiton (among many other things)</p>
<p>Second: you will se... | 122 |
implement classification | Implementation of Naive Bayes for text classification in C++ | https://stackoverflow.com/questions/34515035/implementation-of-naive-bayes-for-text-classification-in-c | <p>I am writing a code for implementing Naive Bayes classifier for text classification. I have worked a very small example, <a href="https://web.stanford.edu/class/cs124/lec/naivebayes.pdf" rel="nofollow">please refer page 44</a>, it seems to be working.</p>
<ol>
<li>But I want know whether the implementation is corre... | 123 | |
implement classification | flask image classification ML model API implementation | https://stackoverflow.com/questions/61115346/flask-image-classification-ml-model-api-implementation | <p>I try to implement a API for pre-trained resnet(machine learning model). so server can accepts a single valid image file in the request to be analyzed. Returns the output from running the image against the model.</p>
<p>I'm wondering what's the general structure of my api look like. So far I have </p>
<p>app
ap... | 124 | |
implement classification | How to implement Multi label classification with train, validation and test images with Densenet/ResNet | https://stackoverflow.com/questions/60784634/how-to-implement-multi-label-classification-with-train-validation-and-test-imag | <p>I am working on <strong>Multi-Label Image classification</strong> using a dataset having 14,720 training images. I need to implement it using <em>ResNet/DenseNet</em>. I trying to work on it. Could you please suggest me a reference to move forward.</p>
| <p>For creating a multi-label classification problem, you have to bear in mind two different crucial aspects:</p>
<ol>
<li>The activation function to be used is <code>sigmoid</code>, not <code>softmax</code> (like in the multi-class classification problem).</li>
<li>A correct label would be of the form <code>[1,0,1,0,0... | 125 |
implement classification | Implementing Image classification using SVM | https://stackoverflow.com/questions/76801704/implementing-image-classification-using-svm | <p>I am trying to understand SVM and want to do image classification using SVM. I saw some sample codes which use sklearn <a href="https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html" rel="nofollow noreferrer">https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html</a> but even after t... | <p>Here I will try and provide some intuition for SVCs. The code for the figures is at the end.</p>
<hr />
<p><strong>Linear SVCs</strong>
Suppose you have a batch of 2-pixel "images", and each image is labelled either A or B. Here's a sample of 5 images:</p>
<p><a href="https://i.sstatic.net/Cwu8d.png" rel="... | 126 |
implement classification | Log likelihood to implement Naive Bayes for Text Classification | https://stackoverflow.com/questions/5451004/log-likelihood-to-implement-naive-bayes-for-text-classification | <p>I am implementing Naive Bayes algorithm for text classification. I have ~1000 documents for training and 400 documents for testing. I think I've implemented training part correctly, but I am confused in testing part. Here is what I've done briefly:</p>
<p>In my training function:</p>
<pre><code>vocabularySize= Get... | <p>The probability of the data described by a set of features {<em>F1</em>, <em>F2</em>, ..., <em>Fn</em>} belonging in class <em>C</em>, according to the naïve Bayes probability model, is</p>
<pre><code>P(C|F) = P(C) * (P(F1|C) * P(F2|C) * ... * P(Fn|C)) / P(F1, ..., Fn)
</code></pre>
<p>You have all the terms (in l... | 127 |
implement classification | Svm Implementation in java - 1/0 classification | https://stackoverflow.com/questions/19899410/svm-implementation-in-java-1-0-classification | <p>I have done SVM using 1/-1 classification.</p>
<p>i.e. by checking sign of decision function <code>wTrans * X - gamma</code></p>
<pre><code>if(decfun<0)
setclasslabel to -1
else
setclasslabel to 1
</code></pre>
<p>What about in 1/0 classification. </p>
<p>Is that the same thing?</p>
| <p>yes, its a same thing.
In your mentioned SVM classification ,you are classifying data into two classes (1/-1) i.e you are just setting them label as 1 or -1.Main concept is to classify data into two classes and label them, so instead of -1 u can label 0 to that class.</p>
<pre><code> if(decfun<0)
setclassl... | 128 |
implement classification | Trying to implement predictRaw() for classification model in Apache Spark | https://stackoverflow.com/questions/45957112/trying-to-implement-predictraw-for-classification-model-in-apache-spark | <p>The developer API example (<a href="https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala" rel="nofollow noreferrer">https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/ml/DeveloperApiExample.scala</a>) giv... | <p>I think I have worked this out. The Spark DeveloperAPI example is very confusing because predictRaw() computes a confidence interval for a logistic-regression type example. However what predictRaw() is actually supposed to do, when implementing ClassificationModel, is predict a vector of output labels for every ith ... | 129 |
implement classification | Implement metrics using XLMRoBERTa model for text classification | https://stackoverflow.com/questions/72515966/implement-metrics-using-xlmroberta-model-for-text-classification | <p>I have created script for binary (0 and 1) text classification using XLM-ROBERTa model. I would like to put metrics (as Binary Cross-Entropy) but also early stopping with patience of 15.</p>
<p>But I have a problem. I tried to use the path <code>model.compile</code> and <code>model.fit</code>, but XLM-RoBertaForSequ... | <p><code>XLMRobertaForSequenceClassification</code> and other classes of the "ForSequenceClassification" family assume classification into multiple classes and use categorical cross-entropy as the loss function. The class is just a lightweight wrapper of the <code>XLMRoberta</code> class.</p>
<p>If you want t... | 130 |
implement classification | Python Implementation of Logistic Regression as Regression (Not Classification!) | https://stackoverflow.com/questions/65268985/python-implementation-of-logistic-regression-as-regression-not-classification | <p>I have a regression problem on which I want to use logistic regression - not logistic classification - because my target variables <code>y</code> are continuopus quantities between 0 and 1. However, the common implementations of logistic regression in Python seem to be exclusively logistic classification. I've also ... | <p>In statsmodels both GLM with family Binomial and discrete model Logit allow for a continuous target variable as long as the values are restricted to interval [0, 1].</p>
<p>Similarly, Poisson is very useful to model non-negative valued continuous data.</p>
<p>In these cases, the model is estimated by quasi maximum l... | 131 |
implement classification | How to implement Grad-CAM in a classification app | https://stackoverflow.com/questions/69881311/how-to-implement-grad-cam-in-a-classification-app | <p>I am building a Medical Image classification app,
Is there a way to intergrate <code>Grad-CAM</code> into the model so that when images are classified they return with <code>class activation map</code>, Or the Grad-CAM functionality is to be added in the app independant from the model?I need the app to classify a di... | 132 | |
implement classification | Implement a Regression/Classification Neural Network in Python | https://stackoverflow.com/questions/47626075/implement-a-regression-classification-neural-network-in-python | <h3>Problem Context</h3>
<p>I am trying to learn Neural Networks in Python, & I've developed an implementation of a Logistic Regression based NN.</p>
<p>Here is the code - </p>
<pre><code>import numpy as np
# Input array
X = np.array([[1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 0, 1]])
# Output
y = np.array([[1], [1], ... | <p>You should try to remove sigmoid function on your output.</p>
<p>As for linear regression, output range may be large, while output of sigmoid or tanh function is [0, 1] or [-1, 1], which makes minimize of error function not possible. </p>
<p>======= UPDATE ======</p>
<p>I try to accomplish it in tensorflow, the c... | 133 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.