# linear or non linear Regression #127

Closed
opened this Issue Nov 14, 2018 · 2 comments

Projects
None yet
3 participants

### kareem1925 commented Nov 14, 2018

 can someone please suggest a way to do regression using this great library? thanks
Member

### co9olguy commented Nov 14, 2018

 Hi @kareem1925, Thanks for your interest in the library. Typically the github issues page isn't the best place to ask this sort of question (it's more for issues with the code/bugs, etc.), but we haven't yet set up a public forum for pennylane questions (should be coming soon). I attach a brief toy example below for how to do linear regression in PennyLane. Hopefully it can be modified to suit your needs 😄 ``````import pennylane as qml from pennylane import numpy as np x = np.linspace(-1,1,10) np.random.seed(0) m,b = 0.5, 1.2 y_data = m * x + b + 0.1 * np.random.randn(10) def y_pred(weights): return weights[0] * x + weights[1] def cost(weights): y_pred_ = y_pred(weights) mse = np.mean((y_data - y_pred_) ** 2) return mse opt = qml.GradientDescentOptimizer(0.5) init_weights = [0.0, 0.0] weights = init_weights for step in range(20): weights = opt.step(cost, weights) print(cost(weights)) import matplotlib.pyplot as plt plt.scatter(x,y_data) plt.plot(x, y_pred(weights),'r') ``````

Member

### josh146 commented Nov 16, 2018

 Hi @kareem1925, just letting you know we now have a PennyLane discussion forum: https://discuss.pennylane.ai. Feel free to post your PennyLane regression questions there, and we will aim to answer as soon as possible :)