Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:12:24+00:00 2026-06-18T06:12:24+00:00

I was going to test my implementation of the sklearn support vector regression package

  • 0

I was going to test my implementation of the sklearn support vector regression package by running it on the boston housing prices dataset that ships with sklearn (sklearn.datasets.load_boston).

After playing around with it for a while (trying different regularization and tube parameters, randomization of cases and crossvalidation) and consistently predicting a flat line I am now at a loss for where I am failing. Even more striking is that when I use the diabetes dataset that also comes with the sklearn.datasets package (load_diabetes) I get a much nicer prediction.

Here is the code for replication:

import numpy as np
from sklearn.svm import SVR
from matplotlib import pyplot as plt
from sklearn.datasets import  load_boston
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression

# data = load_diabetes()
data = load_boston()
X = data.data
y = data.target

# prepare the training and testing data for the model
nCases = len(y)
nTrain = np.floor(nCases / 2)
trainX = X[:nTrain]
trainY = y[:nTrain]
testX  = X[nTrain:]
testY = y[nTrain:]

svr = SVR(kernel='rbf', C=1000)
log = LinearRegression()

# train both models
svr.fit(trainX, trainY)
log.fit(trainX, trainY)

# predict test labels from both models
predLog = log.predict(testX)
predSvr = svr.predict(testX)

# show it on the plot
plt.plot(testY, testY, label='true data')
plt.plot(testY, predSvr, 'co', label='SVR')
plt.plot(testY, predLog, 'mo', label='LogReg')
plt.legend()
plt.show()

Now my question is: has anyone of you successfully used this dataset with a support vector regression model or has an idea of what I am doing wrong? I am very thankful for your suggestions!

Here are the results of the above script this result:
results of running on the load_boston dataset

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:12:26+00:00Added an answer on June 18, 2026 at 6:12 am

    Change the kernel from rbf to linear will solve the problem. If you want to use rbf, try some different parameters, especially for gamma. The default gamma (1/# features) is too large for your case.

    enter image description here

    This is the parameter I used for linear kernel SVR:

    svr = SVR(kernel='linear', C=1.0, epsilon=0.2)
    

    I plotted both training data labels and testing data labels. You might notice that the distribution is not uniform for training data. This made the model lacks data for training when 5 < y < 15. So I did some shuffling of data and set the training data to use 66% of your data.

    nTrain = np.floor(nCases *2.0 / 3.0)
    import random
    ids = range(nCases)
    random.shuffle(ids)
    
    trainX,trainY,testX,testY = [],[],[],[]
    for i, idx in enumerate(ids):
        if i < nTrain:
            trainX.append(X[idx])
            trainY.append(y[idx])
        else:
            testX.append(X[idx])
            testY.append(y[idx])
    

    This is what I get:

    enter image description here

    Visually it looks better for both regressors in terms of prediction errors.

    Here is one working example of rbf kernel SVR:

    svr = SVR(kernel='rbf',  C=1.0, epsilon=0.2, gamma=.0001)
    

    The result looks like:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of test accounts that are going to be created but
I am new in MVC3 i am going to create a MVC3 test project
I realize I'm going to get flamed for not simply writing a test myself...
I'm writing a selenium grid test suite which is going to be run on
<div> <div>test</div> </div> $(div:contains('test')).css('display','none'); I know I am going to kick myself on this.
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Long story short, I want to test my clone implementation of the android.os.Bundle class
The following test shows that Async.Sleep in F# 2.0 can not be canceled immediately.
I've been looking for a C++ SQL library implementation that is simple to hook
I have a currently running PHP application that I want to add real-time feed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.