In: Computer Science
Suppose we have a dataset DD in a regression problem.
What will happen to the in-sample error of linear regression using polynomials of degree dd as d→∞d→∞?
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()
#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);
}