Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # MC886.py
- #
- # Copyright 2017 Andre Muricy <ra134949@lazaro.lab.ic.unicamp.br>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- #
- import sklearn
- x = [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
- y = [-53.9, -28.5, -20.7, -3.6, -9.8, 5.0, 4.2, 5.1, 11.4, 27.4, 44.0]
- def fun(a, b, c, d, xi):
- res = a*xi*xi*xi + b*xi*xi + c*xi + d
- return res
- def gun(a, b, c, d):
- acc = 0
- for i in range(0, len(x)):
- acc = acc + ( y[i] - fun(a, b, c, d, x[i]) ) * ( y[i] - fun(a, b, c, d, x[i]) )
- return acc
- print (gun(0, 0, 0, 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement