Question

In: Computer Science

Suppose we have a dataset DD in a regression problem. What will happen to the in-sample...

Suppose we have a dataset DD in a regression problem.

  1. What will happen to the in-sample error of linear regression using polynomials of degree dd as d→∞d→∞?

  2. What will happen to the out-of-sample error of linear regression as dd increases?

You can use the output of the code below to help you form your answer.

CODE BELOW:

xmin,xmax = 0,4*np.pi
x = np.linspace(xmin,xmax,1000)
D = 14

N = 100
shuff = np.random.permutation(len(x))
x_pts = np.array(sorted(x[shuff][:N]))

K = 200
train_vals = np.zeros(D*K).reshape(K,D)
test_vals = np.zeros(D*K).reshape(K,D)
noise = np.random.randn(N)
y = np.sin(x_pts)+ noise/7

for k in range(K):
    shuff = np.random.permutation(len(x))
    x_pts = np.array(sorted(x[shuff][:N]))
    noise = np.random.randn(N)
    y = np.sin(x_pts)+ noise/7
    for i,deg in enumerate(range(D)):
        X = np.ones(N*deg).reshape(N,deg)
        for j in range(1,deg):
            X[:,j] = x_pts**j
        X_train,X_test,y_train,y_test = test_train_split(X,y,0.13)

        w = linear_fit(X_train,y_train)

        g_train = linear_predict(X_train,w)
        g_test = linear_predict(X_test,w)

        r_train = RMSE(g_train,y_train)
        r_test = RMSE(g_test,y_test)
        train_vals[k][i] = r_train
        test_vals[k][i] = r_test

tr_vals = np.mean(train_vals,axis=0)
te_vals = np.mean(test_vals,axis=0)

plt.plot(range(D),tr_vals)
plt.title("In sample error as a function of model complexity")
plt.xlabel("Polynomial degree")
plt.ylabel("RMSE")
plt.show()
plt.title("Out of sample error as a function of model complexity")
plt.plot(range(D),te_vals)
plt.xlabel("Polynomial degree")
plt.ylabel("RMSE")

plt.axis([0,D,0,2])
plt.show()

Solutions

Expert Solution

#include<stdio.h>
#include<stdlib.h>
struct node{
   int data;
   struct node *next;
};
void printlist(struct node *h){
   while(h != NULL){
       printf("%d ",h->data);
       h = h->next;
   }
}

int main(){
   struct node *start=NULL;
   int a,i;
   printf("Enter the no.of Nodes:");
   scanf("%d",&a);
   for(i=0;i<a;i++){
       struct node *newNode = (struct node *)malloc(sizeof(struct node));
       printf("Enter the data:");
       scanf("%d",&newNode->data);
       newNode->next = NULL;
       if(start==NULL)
           start = newNode;
       else{
           struct node *ptr = start;
           while(ptr->next!=NULL)
               ptr = ptr->next;
           ptr->next = newNode;
       }
   }
   printf("Linked List is:\n");
   printlist(start);
   printf("\nEnter the reversing the list:\n");
   struct node *current = start,*pre = NULL,*nex;
   while(current!=NULL){
       nex = current->next;
       current->next = pre;
       pre = current;
       current = nex;
   }
   start = pre;
   printlist(start);
}


Related Solutions

Suppose there is a decrease in the price of butter. What do we expect to happen...
Suppose there is a decrease in the price of butter. What do we expect to happen to the demand for bread? Assume that bread and butter are often consumed together. Select the correct answer below: There will be a decrease in demand for bread. There will be an increase in demand for bread. There will be no change in the demand for bread and no movement along the demand curve. There will be no change in the demand for bread,...
Suppose that (Yi, Xi) satisfy the assumptions we made in the regression analysis. A random sample...
Suppose that (Yi, Xi) satisfy the assumptions we made in the regression analysis. A random sample of size n = 250 is drawn and yields Yi =5.4 + 3.2×Xi, R2 =0.26, SER=6.2 (3.1) (1.5) (i) TestH0 :β1 =0vs. H1 :β1 ̸=0atthe5%level. (ii) Construct a 95% confidence interval for β1. (iii) Suppose you learned that Yi and Xi were independent. Would you be surprised? Explain. (iv) Suppose that Yi and Xi are independent, and many samples of size n = 250...
Python. 5) What will the code below do? (Assume that we have a dataset df with...
Python. 5) What will the code below do? (Assume that we have a dataset df with these two columns named Occupation' and 'Age') df.groupby('Occupation')['Age'].mean() a) It will return the average age per occupation b) It will return an error c) It will return the total age per occupation d) None of the options 6) df.describe() will return basic descriptive statistics only for numerical variables True/False ? 7) Pandas dataframes can be converted into numpy arrays Truse/False ?
What is regression? How regression is used ? What regression indicate? How do we analyze regression?...
What is regression? How regression is used ? What regression indicate? How do we analyze regression? (In terms of coefficient, t stats, pvalue)? How do write an anlysis of a company using regression? What significat regression means ?
1. Suppose we have the regression y i = β 0 + β 1 ⋅ x...
1. Suppose we have the regression y i = β 0 + β 1 ⋅ x i + ϵ i Measurement error in I. y will cause the ols estimates to be bias II. x will cause attenuation bias in the estimate of β 1 III. y will cause the standard error of β 1to shrink IV. x may cause the estimate of β 1to be statistically insignificant A. II and IV only B. II and III only C. I,...
The dataset HomesForSaleCA contains a random sample of 30 houses for sale in California. Suppose that...
The dataset HomesForSaleCA contains a random sample of 30 houses for sale in California. Suppose that we are interested in predicting the Size (in thousands of square feet) for such homes. State Price Size Beds Baths CA 500 3.2 5 3.5 CA 995 3.7 4 3.5 CA 609 2.2 4 3 CA 1199 2.8 3 2.5 CA 949 1.4 3 2 CA 415 1.7 3 2.5 CA 895 2.1 3 2 CA 775 1.6 3 3 CA 109 0.6 1...
What can we expect to happen to R-squared and adjusted R-squared after including an additional explanatory variable to a regression?
What can we expect to happen to R-squared and adjusted R-squared after including an additional explanatory variable to a regression?O Both R-squared and adjusted R-squared will increase.O Both R-squared and adjusted R-squared will decrease.O R-squared will decrease but adjusted R-squared will increase.O R-squared will increase but adjusted R-squared will decrease.O More information is needed to answer.
Suppose that for a dataset the mean is known. Using the 25 random samples, we computed...
Suppose that for a dataset the mean is known. Using the 25 random samples, we computed the sample variance as s^2=0.001. a) Does the data support the claim that the true standard deviation is less than 0.05? (use alpha = 0.05 and alternative hypothesis sigma^2 < 0.0025) b) Compute a two-sided 95% confidence interval for the true variance of the data.
You have a dataset of the average number of chirps per minute for a sample of...
You have a dataset of the average number of chirps per minute for a sample of 30 crickets. You find that the mean number of chirps per minute is 40 and that the number of chirps per minute has a standard deviation of 5 chirps. You want to test that the mean number of chirps per minute for a cricket is greater than 38 using a significance level of .05. What is the value of your test statistic? Round your...
Suppose, for a random sample selected from a normal population, we have the values of the...
Suppose, for a random sample selected from a normal population, we have the values of the sample mean x ̄ = 67.95 and the standard deviation s = 9. a. Construct a 95% confidence interval for population mean μ assuming the sample size n = 16. b. Construct a 90% confidence interval for population mean μ assuming n = 16. c. Obtain the width of the confidence intervals calculated in a and b. Is the width of 90% confidence interval...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT