├── Demo-Parallel_Grid_Search_SARIMAX
├── Demo_Parallel_Grid_Search_SARIMA.ipynb
├── README.md
├── Test_0qrQsBZ.csv
└── Train_SU63ISt.csv
├── LICENSE
├── Non-parametric Confidence Interval
├── Non_parametric_Confidence_Interval.ipynb
└── README.md
├── PipelineFoundation
├── LICENSE
├── Pipeline_Experiment.ipynb
└── README.md
├── Predicted_R-squared
├── .ipynb_checkpoints
│ └── Predicted_R-squared-checkpoint.ipynb
├── PredictedR2.csv
├── Predicted_R-squared.ipynb
└── README.md
├── README.md
└── SleepyOne
├── README.md
└── index.html
/Demo-Parallel_Grid_Search_SARIMAX/README.md:
--------------------------------------------------------------------------------
1 | #iamJustAStudent - Let's study AI/ML together : http://iamjustastudent.com
2 | # Demo-Parallel_Grid_Search_SARIMAX
3 | Python code - How to fine tune SARIMAX hyperparams using parallel threads on a multi-core GPU, using joblib library.
4 | Read Complete Tutorial at: https://medium.com/analytics-vidhya/fine-tune-sarima-hyperparams-using-parallel-processing-with-joblib-step-by-step-python-code-2037fec1659
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Non-parametric Confidence Interval/Non_parametric_Confidence_Interval.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Non-parametric Confidence Interval.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": []
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | }
14 | },
15 | "cells": [
16 | {
17 | "cell_type": "markdown",
18 | "metadata": {
19 | "id": "ZCKkphFiGk75",
20 | "colab_type": "text"
21 | },
22 | "source": [
23 | "#Confidence Interval of Non-Parametric Statistical Tests"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "metadata": {
29 | "id": "mHmGZtGnwXAg",
30 | "colab_type": "code",
31 | "colab": {}
32 | },
33 | "source": [
34 | "# methodology behind the code referenced from the British Medical Journal,\n",
35 | "# volume 296, 21 May 1988:\n",
36 | "# \"Calculating confidence intervals for some non-parametric analyses\" by \n",
37 | "# M J Campbell & M J Gardner\n",
38 | "# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2545906/pdf/bmj00286-0037.pdf\n",
39 | "\n",
40 | "# worked examples referenced from the book: \n",
41 | "# Statistics at Square One by M J Campbell & T D V Swinscow\n",
42 | "# https://www.amazon.in/Statistics-Square-One-Michael-Campbell/dp/1405191007"
43 | ],
44 | "execution_count": 0,
45 | "outputs": []
46 | },
47 | {
48 | "cell_type": "code",
49 | "metadata": {
50 | "id": "46ORWbg2gDtA",
51 | "colab_type": "code",
52 | "colab": {}
53 | },
54 | "source": [
55 | "# custom func for confidence interval for differences \n",
56 | "# for (non-Gaussian unpaired data). Example: Mann-Whitney U test\n",
57 | "\n",
58 | "import numpy as np\n",
59 | "\n",
60 | "def non_param_unpaired_CI(sample1, sample2, conf):\n",
61 | " n1 = len(sample1) \n",
62 | " n2 = len(sample2) \n",
63 | " alpha = 1-conf \n",
64 | " N = stats.norm.ppf(1 - alpha/2) \n",
65 | "\n",
66 | " # The confidence interval for the difference between the two population\n",
67 | " # medians is derived through the n x m differences.\n",
68 | " diffs = sorted([i-j for i in sample1 for j in sample2])\n",
69 | " \n",
70 | " # the Kth smallest to the Kth largest of the n x m differences then determine \n",
71 | " # the confidence interval, where K is:\n",
72 | " k = np.math.ceil(n1*n2/2 - (N * (n1*n2*(n1+n2+1)/12)**0.5))\n",
73 | " \n",
74 | " CI = (round(diffs[k-1],3), round(diffs[len(diffs)-k],3))\n",
75 | " return CI"
76 | ],
77 | "execution_count": 0,
78 | "outputs": []
79 | },
80 | {
81 | "cell_type": "code",
82 | "metadata": {
83 | "id": "hZzwH0yA02ch",
84 | "colab_type": "code",
85 | "colab": {}
86 | },
87 | "source": [
88 | "# custom func for confidence interval for differences \n",
89 | "# for (non-Gaussian paired data) Example: Wilcoxon signed-rank test\n",
90 | "\n",
91 | "import numpy as np\n",
92 | "import operator\n",
93 | "\n",
94 | "def non_param_paired_CI(sample1, sample2, conf):\n",
95 | " n = len(sample1) \n",
96 | " alpha = 1-conf \n",
97 | " N = stats.norm.ppf(1 - alpha/2) \n",
98 | "\n",
99 | " # The confidence interval for the difference between the two population\n",
100 | " # medians is derived through the n(n+1)/2 possible averaged differences.\n",
101 | " diff_sample = sorted(list(map(operator.sub, sample2, sample1)))\n",
102 | " averages = sorted([(s1+s2)/2 for i, s1 in enumerate(diff_sample) for _, s2 in enumerate(diff_sample[i:])])\n",
103 | "\n",
104 | " # the Kth smallest to the Kth largest of the averaged differences then \n",
105 | " # determine the confidence interval, where K is:\n",
106 | " k = np.math.ceil(n*(n+1)/4 - (N * (n*(n+1)*(2*n+1)/24)**0.5))\n",
107 | "\n",
108 | " CI = (round(averages[k-1],3), round(averages[len(averages)-k],3))\n",
109 | " return CI"
110 | ],
111 | "execution_count": 0,
112 | "outputs": []
113 | },
114 | {
115 | "cell_type": "markdown",
116 | "metadata": {
117 | "id": "5kOfkAAgBOFz",
118 | "colab_type": "text"
119 | },
120 | "source": [
121 | "## Worked Examples"
122 | ]
123 | },
124 | {
125 | "cell_type": "markdown",
126 | "metadata": {
127 | "id": "V4PmwYr1L6NB",
128 | "colab_type": "text"
129 | },
130 | "source": [
131 | "###Mann-Whitney *U* test \n",
132 | "###*for unpaired, non-normal continuous output data*"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "metadata": {
138 | "id": "-iURL33ydog3",
139 | "colab_type": "code",
140 | "colab": {}
141 | },
142 | "source": [
143 | "# A senior registrar in the rheumatology clinic of a district hospital\n",
144 | "# has designed a clinical trial of a new drug for rheumatoid arthritis.\n",
145 | "# Twenty patients were randomized into two groups of 10 to\n",
146 | "# receive either the standard therapy A or a new treatment B. The\n",
147 | "# plasma globulin fractions after treatment are listed in the Table below.\n",
148 | "\n",
149 | "# Ques Posed : We wish to test whether the new treatment has changed the \n",
150 | "# plasma globulin (and we are worried about the assumption of Normality)."
151 | ],
152 | "execution_count": 0,
153 | "outputs": []
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {
158 | "id": "0Qkc3npueltG",
159 | "colab_type": "text"
160 | },
161 | "source": [
162 | ""
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "metadata": {
168 | "id": "GpLX5L-KhILA",
169 | "colab_type": "code",
170 | "colab": {}
171 | },
172 | "source": [
173 | "# H0 (null hypothesis): plasma globulin fraction is not affected by either treatments."
174 | ],
175 | "execution_count": 0,
176 | "outputs": []
177 | },
178 | {
179 | "cell_type": "code",
180 | "metadata": {
181 | "id": "7ugN7idQemKT",
182 | "colab_type": "code",
183 | "outputId": "2a2a012a-da61-4047-ccf9-6bc0fcb0eb7b",
184 | "colab": {
185 | "base_uri": "https://localhost:8080/",
186 | "height": 68
187 | }
188 | },
189 | "source": [
190 | "import numpy as np\n",
191 | "from scipy import stats\n",
192 | "import operator\n",
193 | "\n",
194 | "# given\n",
195 | "conf = 0.95\n",
196 | "sample1 = [38,26,29,41,36,31,32,30,35,33]\n",
197 | "sample2 = [45,28,27,38,40,42,39,39,34,45]\n",
198 | "\n",
199 | "# mann-whitney\n",
200 | "# we need to use alternative='two-sided'. The use_continuity param is set to \n",
201 | "# 'False' simply to compare with the findings of the book, 'Statistics at Square \n",
202 | "# One'. Otherwise, I think it can be left at its default value of 'True'.\n",
203 | "stat, p = stats.mannwhitneyu(sample1, sample2, use_continuity=False, alternative='two-sided')\n",
204 | "print(f\"p: {round(p, 3)}\")\n",
205 | "\n",
206 | "if p<=(1-conf):\n",
207 | " print(\"Reject H0. Plasma globulin fraction looks likely to be affected by the treatments.\")\n",
208 | "else:\n",
209 | " print(\"Failed to reject H0. Plasma globulin fraction does not look likely to be affected by either treatments.\")\n",
210 | "\n",
211 | "# confidence interval\n",
212 | "diff_median = np.median( list(map(operator.sub, sample1, sample2)) )\n",
213 | "lower, upper = non_param_unpaired_CI(sample1, sample2, conf)\n",
214 | "\n",
215 | "print(f\"{100*conf} % confidence that the median of the samples' diff lies b/w {lower} and {upper}.\")"
216 | ],
217 | "execution_count": 4,
218 | "outputs": [
219 | {
220 | "output_type": "stream",
221 | "text": [
222 | "p: 0.075\n",
223 | "Failed to reject H0. Plasma globulin fraction does not look likely to be affected by either treatments.\n",
224 | "95.0 % confidence that the median of the samples' diff lies b/w -10 and 1.\n"
225 | ],
226 | "name": "stdout"
227 | }
228 | ]
229 | },
230 | {
231 | "cell_type": "code",
232 | "metadata": {
233 | "id": "Y53xezOimbOF",
234 | "colab_type": "code",
235 | "colab": {}
236 | },
237 | "source": [
238 | ""
239 | ],
240 | "execution_count": 0,
241 | "outputs": []
242 | },
243 | {
244 | "cell_type": "markdown",
245 | "metadata": {
246 | "id": "Psw0BxGfJ0Zv",
247 | "colab_type": "text"
248 | },
249 | "source": [
250 | "###Wilcoxon rank test (used for paired data)\n",
251 | "###*for*\n",
252 | "###*(a) Ordinal output data or* \n",
253 | "###*(b) Quantitative output data (discrete or non-normal)*"
254 | ]
255 | },
256 | {
257 | "cell_type": "code",
258 | "metadata": {
259 | "id": "iSjyrAvlM-yW",
260 | "colab_type": "code",
261 | "colab": {}
262 | },
263 | "source": [
264 | "# Boogert et al. used ultrasound to record\n",
265 | "# fetal movements before and after chorionic villus sampling. The\n",
266 | "# percentage of time the fetus spent moving is given in the Table below\n",
267 | "# for 10 pregnant women.\n",
268 | "\n",
269 | "# Ques Posed : Does the chorionic villus sampling process change the \n",
270 | "# fetus movement time?\n",
271 | "\n",
272 | "# If we are concerned that the differences in percentage of time\n",
273 | "# spent moving are unlikely to be Normally distributed we could use\n",
274 | "# the Wilcoxon signed rank test using the following assumptions:"
275 | ],
276 | "execution_count": 0,
277 | "outputs": []
278 | },
279 | {
280 | "cell_type": "code",
281 | "metadata": {
282 | "id": "MSenWFtjKIGH",
283 | "colab_type": "code",
284 | "colab": {}
285 | },
286 | "source": [
287 | "# Assumptions:\n",
288 | "# 1. The paired differences are independent.\n",
289 | "# 2. The differences come from a symmetrical distribution.\n",
290 | "\n",
291 | "# dataset :"
292 | ],
293 | "execution_count": 0,
294 | "outputs": []
295 | },
296 | {
297 | "cell_type": "markdown",
298 | "metadata": {
299 | "id": "_Gg4rSrxKK3v",
300 | "colab_type": "text"
301 | },
302 | "source": [
303 | ""
304 | ]
305 | },
306 | {
307 | "cell_type": "code",
308 | "metadata": {
309 | "id": "v6KClOeutLTs",
310 | "colab_type": "code",
311 | "colab": {}
312 | },
313 | "source": [
314 | ""
315 | ],
316 | "execution_count": 0,
317 | "outputs": []
318 | },
319 | {
320 | "cell_type": "code",
321 | "metadata": {
322 | "id": "f1BxtFVkKLJI",
323 | "colab_type": "code",
324 | "outputId": "c22a6525-8a33-428e-9a37-aedd3427b39b",
325 | "colab": {
326 | "base_uri": "https://localhost:8080/",
327 | "height": 68
328 | }
329 | },
330 | "source": [
331 | "import numpy as np\n",
332 | "from scipy import stats\n",
333 | "import operator\n",
334 | "\n",
335 | "# given\n",
336 | "conf = 0.95\n",
337 | "before = [25,24,28,15,20,23,21,20,20,27]\n",
338 | "after = [18,27,25,20,17,24,24,22,19,19]\n",
339 | "\n",
340 | "# wilcoxon\n",
341 | "statistic, p = stats.wilcoxon(before, after)\n",
342 | "print(f\"p: {round(p,3)}\")\n",
343 | "\n",
344 | "if p<=(1-conf):\n",
345 | " print(\"Reject H0. The sampling process seems to change fetal movements.\")\n",
346 | "else:\n",
347 | " print(\"Failed to reject H0. The sampling process does not seem to change fetal movements.\")\n",
348 | "\n",
349 | "# confidence interval\n",
350 | "diff_median = np.median( list(map(operator.sub, before, after)) )\n",
351 | "lower, upper = non_param_paired_CI(before, after, conf)\n",
352 | "\n",
353 | "print(f\"{100*conf} % confidence that the median of the samples' diff lies b/w {lower} and {upper}.\")"
354 | ],
355 | "execution_count": 6,
356 | "outputs": [
357 | {
358 | "output_type": "stream",
359 | "text": [
360 | "p: 0.681\n",
361 | "Failed to reject H0. The sampling process does not seem to change fetal movements.\n",
362 | "95.0 % confidence that the median of the samples' diff lies b/w -4.0 and 2.5.\n"
363 | ],
364 | "name": "stdout"
365 | }
366 | ]
367 | },
368 | {
369 | "cell_type": "code",
370 | "metadata": {
371 | "id": "6NUmIDh-25v4",
372 | "colab_type": "code",
373 | "colab": {}
374 | },
375 | "source": [
376 | ""
377 | ],
378 | "execution_count": 0,
379 | "outputs": []
380 | }
381 | ]
382 | }
--------------------------------------------------------------------------------
/Non-parametric Confidence Interval/README.md:
--------------------------------------------------------------------------------
1 | #iamJustAStudent - Let's study AI/ML together : http://iamjustastudent.com
2 | # How to Calculate Confidence Intervals for Non-Parametric Statistical Tests in Python
3 | Complete python code with worked examples for Mann-Whitney U test and Wilcoxon signed-rank test.
4 |
5 | Read the complete tutorial at: https://towardsdatascience.com/prepare-dinner-save-the-day-by-calculating-confidence-interval-of-non-parametric-statistical-29d031d079d0
6 |
7 | View code in Google Colab: https://colab.research.google.com/drive/1E_l4-Z6132DGZoVRqpecn6I3Ny62Nksj
8 |
--------------------------------------------------------------------------------
/PipelineFoundation/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/PipelineFoundation/Pipeline_Experiment.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Pipeline Experiment.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyMYwerXEgiwGSEXN767uP4N",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | ""
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "id": "U91hkLpi-SBV",
32 | "colab_type": "text"
33 | },
34 | "source": [
35 | "#Imports"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "metadata": {
41 | "id": "8cjFGNq0P_re",
42 | "colab_type": "code",
43 | "colab": {}
44 | },
45 | "source": [
46 | "import numpy as np\n",
47 | "import pandas as pd\n",
48 | "import warnings\n",
49 | "warnings.filterwarnings('ignore')\n",
50 | "from sklearn.metrics import mean_squared_error\n",
51 | "\n",
52 | "from sklearn.preprocessing import StandardScaler, PowerTransformer\n",
53 | "from sklearn.compose import TransformedTargetRegressor\n",
54 | "from sklearn.pipeline import FeatureUnion, Pipeline, make_pipeline\n",
55 | "from sklearn.base import BaseEstimator, TransformerMixin\n",
56 | "\n",
57 | "from sklearn.linear_model import LinearRegression"
58 | ],
59 | "execution_count": 0,
60 | "outputs": []
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {
65 | "id": "aZ7KzRqK-KHL",
66 | "colab_type": "text"
67 | },
68 | "source": [
69 | "#Pipeline Experiment"
70 | ]
71 | },
72 | {
73 | "cell_type": "code",
74 | "metadata": {
75 | "id": "D13TnX_2_mLi",
76 | "colab_type": "code",
77 | "colab": {}
78 | },
79 | "source": [
80 | "df = pd.DataFrame(columns=['X1', 'X2', 'y'], data=[\n",
81 | " [1,16,9],\n",
82 | " [4,36,16],\n",
83 | " [1,16,9],\n",
84 | " [2,9,8],\n",
85 | " [3,36,15],\n",
86 | " [2,49,16],\n",
87 | " [4,25,14],\n",
88 | " [5,36,17]\n",
89 | "])\n",
90 | "\n",
91 | "### y = X1 + 2 * sqrt(X2)\n",
92 | "\n",
93 | "train = df.iloc[:6]\n",
94 | "test = df.iloc[6:]\n",
95 | "\n",
96 | "train_X = train.drop('y', axis=1)\n",
97 | "train_y = train.y\n",
98 | "\n",
99 | "test_X = test.drop('y', axis=1)\n",
100 | "test_y = test.y"
101 | ],
102 | "execution_count": 0,
103 | "outputs": []
104 | },
105 | {
106 | "cell_type": "code",
107 | "metadata": {
108 | "id": "Wd_emlUpBbig",
109 | "colab_type": "code",
110 | "colab": {
111 | "base_uri": "https://localhost:8080/",
112 | "height": 90
113 | },
114 | "outputId": "d33d7919-f565-4b51-d6b5-cd0dae60604d"
115 | },
116 | "source": [
117 | "# let's see if linear regression is able to predict this properly\n",
118 | "m1 = LinearRegression()\n",
119 | "fit1 = m1.fit(train_X, train_y)\n",
120 | "preds = fit1.predict(test_X)\n",
121 | "print(f\"\\n{preds}\")\n",
122 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds))}\\n\")"
123 | ],
124 | "execution_count": 29,
125 | "outputs": [
126 | {
127 | "output_type": "stream",
128 | "text": [
129 | "\n",
130 | "[13.72113586 16.93334467]\n",
131 | "RMSE: 0.20274138822160603\n",
132 | "\n"
133 | ],
134 | "name": "stdout"
135 | }
136 | ]
137 | },
138 | {
139 | "cell_type": "code",
140 | "metadata": {
141 | "id": "zQayYrzmDWE7",
142 | "colab_type": "code",
143 | "colab": {
144 | "base_uri": "https://localhost:8080/",
145 | "height": 145
146 | },
147 | "outputId": "b9b3321c-e5b9-4777-d673-8bb07def11d3"
148 | },
149 | "source": [
150 | "# what if we square-root X2 and multiply by 2?\n",
151 | "train_X.X2 = 2 * np.sqrt(train_X.X2)\n",
152 | "test_X.X2 = 2 * np.sqrt(test_X.X2)\n",
153 | "print(test_X)\n",
154 | "m2 = LinearRegression()\n",
155 | "fit2 = m2.fit(train_X, train_y)\n",
156 | "preds = fit2.predict(test_X)\n",
157 | "print(f\"\\n{preds}\")\n",
158 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds))}\\n\")"
159 | ],
160 | "execution_count": 30,
161 | "outputs": [
162 | {
163 | "output_type": "stream",
164 | "text": [
165 | " X1 X2\n",
166 | "6 4 10.0\n",
167 | "7 5 12.0\n",
168 | "\n",
169 | "[14. 17.]\n",
170 | "RMSE: 1.2560739669470201e-15\n",
171 | "\n"
172 | ],
173 | "name": "stdout"
174 | }
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "metadata": {
180 | "id": "xMrbwYDDNFKu",
181 | "colab_type": "code",
182 | "colab": {}
183 | },
184 | "source": [
185 | "# a perfect prediction, because the data after transformation, fits a perfect linear trend.\n",
186 | "# let's restore the data back to original, and do this via custom transformers using pipeline.\n",
187 | "train = df.iloc[:6]\n",
188 | "test = df.iloc[6:]\n",
189 | "\n",
190 | "train_X = train.drop('y', axis=1)\n",
191 | "train_y = train.y\n",
192 | "\n",
193 | "test_X = test.drop('y', axis=1)\n",
194 | "test_y = test.y"
195 | ],
196 | "execution_count": 0,
197 | "outputs": []
198 | },
199 | {
200 | "cell_type": "code",
201 | "metadata": {
202 | "id": "SD08IkZP-Lam",
203 | "colab_type": "code",
204 | "colab": {}
205 | },
206 | "source": [
207 | "# references: \n",
208 | "# https://towardsdatascience.com/custom-transformers-and-ml-data-pipelines-with-python-20ea2a7adb65\n",
209 | "# https://machinelearningmastery.com/how-to-transform-target-variables-for-regression-with-scikit-learn/\n",
210 | "# http://zacstewart.com/2014/08/05/pipelines-of-featureunions-of-pipelines.html\n",
211 | "# https://stackoverflow.com/questions/43308042/transformer-initialize-twice-in-pipeline\n",
212 | "\n",
213 | "class ExperimentalTransformer(BaseEstimator, TransformerMixin):\n",
214 | " def __init__(self):\n",
215 | " print('\\n>>>>>>>init() called.\\n')\n",
216 | "\n",
217 | " def fit(self, X, y = None):\n",
218 | " print('\\n>>>>>>>fit() called.\\n')\n",
219 | " return self\n",
220 | "\n",
221 | " def transform(self, X, y = None):\n",
222 | " print('\\n>>>>>>>transform() called.\\n')\n",
223 | " X_ = X.copy() # creating a copy to avoid changes to original dataset\n",
224 | " X_.X2 = 2 * np.sqrt(X_.X2)\n",
225 | " return X_"
226 | ],
227 | "execution_count": 0,
228 | "outputs": []
229 | },
230 | {
231 | "cell_type": "code",
232 | "metadata": {
233 | "id": "spUiscMUPY83",
234 | "colab_type": "code",
235 | "colab": {
236 | "base_uri": "https://localhost:8080/",
237 | "height": 145
238 | },
239 | "outputId": "961ad4f6-5143-442a-8a19-bc986910479d"
240 | },
241 | "source": [
242 | "# without input transformation - to validate that we get the same results as before\n",
243 | "print(\"create pipeline 1\")\n",
244 | "pipe1 = Pipeline(steps=[\n",
245 | " ('linear_model', LinearRegression())\n",
246 | "])\n",
247 | "print(\"fit pipeline 1\")\n",
248 | "pipe1.fit(train_X, train_y)\n",
249 | "print(\"predict via pipeline 1\")\n",
250 | "preds1 = pipe1.predict(test_X)\n",
251 | "print(f\"\\n{preds1}\") # should be [13.72113586 16.93334467]\n",
252 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds1))}\\n\") "
253 | ],
254 | "execution_count": 33,
255 | "outputs": [
256 | {
257 | "output_type": "stream",
258 | "text": [
259 | "create pipeline 1\n",
260 | "fit pipeline 1\n",
261 | "predict via pipeline 1\n",
262 | "\n",
263 | "[13.72113586 16.93334467]\n",
264 | "RMSE: 0.20274138822160603\n",
265 | "\n"
266 | ],
267 | "name": "stdout"
268 | }
269 | ]
270 | },
271 | {
272 | "cell_type": "code",
273 | "metadata": {
274 | "id": "OFTnGVww_kIi",
275 | "colab_type": "code",
276 | "colab": {
277 | "base_uri": "https://localhost:8080/",
278 | "height": 363
279 | },
280 | "outputId": "a86df4fa-fa17-4a43-f87a-07167fff174c"
281 | },
282 | "source": [
283 | "# with input transformation\n",
284 | "print(\"create pipeline 2\")\n",
285 | "pipe2 = Pipeline(steps=[\n",
286 | " ('experimental_trans', ExperimentalTransformer()), # this will trigger a call to __init__\n",
287 | " ('linear_model', LinearRegression())\n",
288 | "])\n",
289 | "\n",
290 | "# an alternate, shorter syntax to do the above, without naming each step, is:\n",
291 | "#pipe2 = make_pipeline(ExperimentalTransformer(), LinearRegression())\n",
292 | "\n",
293 | "print(\"fit pipeline 2\")\n",
294 | "pipe2.fit(train_X, train_y)\n",
295 | "print(\"predict via pipeline 2\")\n",
296 | "preds2 = pipe2.predict(test_X)\n",
297 | "print(f\"\\n{preds2}\") # should be [14. 17.]\n",
298 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds2))}\\n\")"
299 | ],
300 | "execution_count": 34,
301 | "outputs": [
302 | {
303 | "output_type": "stream",
304 | "text": [
305 | "create pipeline 2\n",
306 | "\n",
307 | ">>>>>>>init() called.\n",
308 | "\n",
309 | "fit pipeline 2\n",
310 | "\n",
311 | ">>>>>>>fit() called.\n",
312 | "\n",
313 | "\n",
314 | ">>>>>>>transform() called.\n",
315 | "\n",
316 | "predict via pipeline 2\n",
317 | "\n",
318 | ">>>>>>>transform() called.\n",
319 | "\n",
320 | "\n",
321 | "[14. 17.]\n",
322 | "RMSE: 1.2560739669470201e-15\n",
323 | "\n"
324 | ],
325 | "name": "stdout"
326 | }
327 | ]
328 | },
329 | {
330 | "cell_type": "code",
331 | "metadata": {
332 | "id": "7QAxS_dkSpnC",
333 | "colab_type": "code",
334 | "colab": {}
335 | },
336 | "source": [
337 | "# we've assumed in the transform() function of our ExperimentalTransformer that the column name is X2. Let's not do so and\n",
338 | "# pass the column name via the constructor, __init__()"
339 | ],
340 | "execution_count": 0,
341 | "outputs": []
342 | },
343 | {
344 | "cell_type": "code",
345 | "metadata": {
346 | "id": "qB8bhqpdS-2m",
347 | "colab_type": "code",
348 | "colab": {}
349 | },
350 | "source": [
351 | "class ExperimentalTransformer_2(BaseEstimator, TransformerMixin):\n",
352 | " # add another additional parameter, just for fun, while we are at it\n",
353 | " def __init__(self, feature_name, additional_param = \"Himanshu\"): \n",
354 | " print('\\n>>>>>>>init() called.\\n')\n",
355 | " self.feature_name = feature_name\n",
356 | " self.additional_param = additional_param\n",
357 | "\n",
358 | " def fit(self, X, y = None):\n",
359 | " print('\\n>>>>>>>fit() called.\\n')\n",
360 | " print(f'\\nadditional param ~~~~~ {self.additional_param}\\n')\n",
361 | " return self\n",
362 | "\n",
363 | " def transform(self, X, y = None):\n",
364 | " print('\\n>>>>>>>transform() called.\\n')\n",
365 | " X_ = X.copy() # creating a copy to avoid changes to original dataset\n",
366 | " X_[self.feature_name] = 2 * np.sqrt(X_[self.feature_name])\n",
367 | " return X_"
368 | ],
369 | "execution_count": 0,
370 | "outputs": []
371 | },
372 | {
373 | "cell_type": "code",
374 | "metadata": {
375 | "id": "A_WkBgdkTOLU",
376 | "colab_type": "code",
377 | "colab": {}
378 | },
379 | "source": [
380 | "# take care to keep the parameter name exactly the same in the function argument as well as \n",
381 | "# the class' variable (feature_name). Changing that will cause problems later when we also\n",
382 | "# try to transform the target feature (y). It causes a double-call to __init__ for some reason."
383 | ],
384 | "execution_count": 0,
385 | "outputs": []
386 | },
387 | {
388 | "cell_type": "code",
389 | "metadata": {
390 | "id": "GB6WV6pUTuu-",
391 | "colab_type": "code",
392 | "colab": {
393 | "base_uri": "https://localhost:8080/",
394 | "height": 417
395 | },
396 | "outputId": "bdd1ecc7-285d-4d39-f8f3-d6101bdeeef7"
397 | },
398 | "source": [
399 | "print(\"create pipeline 2\")\n",
400 | "pipe2 = Pipeline(steps=[\n",
401 | " ('experimental_trans', ExperimentalTransformer_2('X2')),\n",
402 | " ('linear_model', LinearRegression())\n",
403 | "])\n",
404 | "print(\"fit pipeline 2\")\n",
405 | "pipe2.fit(train_X, train_y)\n",
406 | "print(\"predict via pipeline 2\")\n",
407 | "preds2 = pipe2.predict(test_X)\n",
408 | "print(f\"\\n{preds2}\") # should be [14. 17.]\n",
409 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds2))}\\n\")"
410 | ],
411 | "execution_count": 38,
412 | "outputs": [
413 | {
414 | "output_type": "stream",
415 | "text": [
416 | "create pipeline 2\n",
417 | "\n",
418 | ">>>>>>>init() called.\n",
419 | "\n",
420 | "fit pipeline 2\n",
421 | "\n",
422 | ">>>>>>>fit() called.\n",
423 | "\n",
424 | "\n",
425 | "additional param ~~~~~ Himanshu\n",
426 | "\n",
427 | "\n",
428 | ">>>>>>>transform() called.\n",
429 | "\n",
430 | "predict via pipeline 2\n",
431 | "\n",
432 | ">>>>>>>transform() called.\n",
433 | "\n",
434 | "\n",
435 | "[14. 17.]\n",
436 | "RMSE: 1.2560739669470201e-15\n",
437 | "\n"
438 | ],
439 | "name": "stdout"
440 | }
441 | ]
442 | },
443 | {
444 | "cell_type": "code",
445 | "metadata": {
446 | "id": "jBLKFfxcVhE5",
447 | "colab_type": "code",
448 | "colab": {}
449 | },
450 | "source": [
451 | "# let's take this a step further by modifying the dataframe to have target as squares of current values:"
452 | ],
453 | "execution_count": 0,
454 | "outputs": []
455 | },
456 | {
457 | "cell_type": "code",
458 | "metadata": {
459 | "id": "uqY60SOGViBG",
460 | "colab_type": "code",
461 | "colab": {}
462 | },
463 | "source": [
464 | "df = pd.DataFrame(columns=['X1', 'X2', 'y'], data=[\n",
465 | " [1,16,81],\n",
466 | " [4,36,256],\n",
467 | " [1,16,81],\n",
468 | " [2,9,64],\n",
469 | " [3,36,225],\n",
470 | " [2,49,256],\n",
471 | " [4,25,196],\n",
472 | " [5,36,289]\n",
473 | "])\n",
474 | "\n",
475 | "### sqrt(y) = X1 + 2 * sqrt(X2)\n",
476 | "\n",
477 | "train = df.iloc[:6]\n",
478 | "test = df.iloc[6:]\n",
479 | "\n",
480 | "train_X = train.drop('y', axis=1)\n",
481 | "train_y = train.y\n",
482 | "\n",
483 | "test_X = test.drop('y', axis=1)\n",
484 | "test_y = test.y"
485 | ],
486 | "execution_count": 0,
487 | "outputs": []
488 | },
489 | {
490 | "cell_type": "code",
491 | "metadata": {
492 | "id": "FSAo6KGzViSe",
493 | "colab_type": "code",
494 | "colab": {
495 | "base_uri": "https://localhost:8080/",
496 | "height": 145
497 | },
498 | "outputId": "2b16b778-bcda-4b00-a700-6e85bc162e30"
499 | },
500 | "source": [
501 | "# let's see model's performance with no input & target transformations:\n",
502 | "print(\"create pipeline 1\")\n",
503 | "pipe1 = Pipeline(steps=[\n",
504 | " ('linear_model', LinearRegression())\n",
505 | "])\n",
506 | "print(\"fit pipeline 1\")\n",
507 | "pipe1.fit(train_X, train_y)\n",
508 | "print(\"predict via pipeline 1\")\n",
509 | "preds1 = pipe1.predict(test_X)\n",
510 | "print(f\"\\n{preds1}\") \n",
511 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds1))}\\n\") "
512 | ],
513 | "execution_count": 41,
514 | "outputs": [
515 | {
516 | "output_type": "stream",
517 | "text": [
518 | "create pipeline 1\n",
519 | "fit pipeline 1\n",
520 | "predict via pipeline 1\n",
521 | "\n",
522 | "[200.34790002 279.04738423]\n",
523 | "RMSE: 7.679804528409077\n",
524 | "\n"
525 | ],
526 | "name": "stdout"
527 | }
528 | ]
529 | },
530 | {
531 | "cell_type": "code",
532 | "metadata": {
533 | "id": "i_PwqZaTVihG",
534 | "colab_type": "code",
535 | "colab": {
536 | "base_uri": "https://localhost:8080/",
537 | "height": 417
538 | },
539 | "outputId": "eb81b244-93a0-42fc-a80e-18a2dc259262"
540 | },
541 | "source": [
542 | "# with input transformation but no target transformation\n",
543 | "print(\"create pipeline 2\")\n",
544 | "pipe2 = Pipeline(steps=[\n",
545 | " ('experimental_trans', ExperimentalTransformer_2('X2')),\n",
546 | " ('linear_model', LinearRegression())\n",
547 | "])\n",
548 | "print(\"fit pipeline 2\")\n",
549 | "pipe2.fit(train_X, train_y)\n",
550 | "print(\"predict via pipeline 2\")\n",
551 | "preds2 = pipe2.predict(test_X)\n",
552 | "print(f\"\\n{preds2}\") \n",
553 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds2))}\\n\")"
554 | ],
555 | "execution_count": 42,
556 | "outputs": [
557 | {
558 | "output_type": "stream",
559 | "text": [
560 | "create pipeline 2\n",
561 | "\n",
562 | ">>>>>>>init() called.\n",
563 | "\n",
564 | "fit pipeline 2\n",
565 | "\n",
566 | ">>>>>>>fit() called.\n",
567 | "\n",
568 | "\n",
569 | "additional param ~~~~~ Himanshu\n",
570 | "\n",
571 | "\n",
572 | ">>>>>>>transform() called.\n",
573 | "\n",
574 | "predict via pipeline 2\n",
575 | "\n",
576 | ">>>>>>>transform() called.\n",
577 | "\n",
578 | "\n",
579 | "[207.42690058 280.94152047]\n",
580 | "RMSE: 9.887192456534303\n",
581 | "\n"
582 | ],
583 | "name": "stdout"
584 | }
585 | ]
586 | },
587 | {
588 | "cell_type": "code",
589 | "metadata": {
590 | "id": "9Ug-zMF0YISg",
591 | "colab_type": "code",
592 | "colab": {}
593 | },
594 | "source": [
595 | "# we'll now write a custom target transformer.\n",
596 | "# this needs 2 functions, one to transform and another to inverse-transform"
597 | ],
598 | "execution_count": 0,
599 | "outputs": []
600 | },
601 | {
602 | "cell_type": "code",
603 | "metadata": {
604 | "id": "TskWUHTcVit_",
605 | "colab_type": "code",
606 | "colab": {}
607 | },
608 | "source": [
609 | "def target_transform(target):\n",
610 | " print('\\n*****************target_transform() called.\\n')\n",
611 | " target_ = target.copy() \n",
612 | " target_ = np.sqrt(target_)\n",
613 | " return target_\n",
614 | "\n",
615 | "def inverse_target_transform(target):\n",
616 | " print('\\n*****************inverse_target_transform() called.\\n')\n",
617 | " target_ = target.copy() \n",
618 | " target_ = target_ ** 2\n",
619 | " return target_"
620 | ],
621 | "execution_count": 0,
622 | "outputs": []
623 | },
624 | {
625 | "cell_type": "code",
626 | "metadata": {
627 | "id": "OwNd-9__Ywx9",
628 | "colab_type": "code",
629 | "colab": {
630 | "base_uri": "https://localhost:8080/",
631 | "height": 799
632 | },
633 | "outputId": "da2ba50d-8f3d-405d-f137-b8abcb7d2c6d"
634 | },
635 | "source": [
636 | "# with input transformation & target transformation\n",
637 | "print(\"create pipeline 3\")\n",
638 | "# no change in input pipeline\n",
639 | "pipe3 = Pipeline(steps=[\n",
640 | " ('experimental_trans', ExperimentalTransformer_2('X2')),\n",
641 | " ('linear_model', LinearRegression())\n",
642 | "])\n",
643 | "\n",
644 | "# create a TargetTransformer \n",
645 | "model = TransformedTargetRegressor(regressor=pipe3, \n",
646 | " func=target_transform, \n",
647 | " inverse_func=inverse_target_transform)\n",
648 | "\n",
649 | "print(\"fit pipeline 3 [fit Model]\")\n",
650 | "# note the different syntax here; we fit the 'model' now, instead of 'pipe3'\n",
651 | "model.fit(train_X, train_y) \n",
652 | "print(\"predict via pipeline 3 [Model]\")\n",
653 | "preds3 = model.predict(test_X) # same here, using 'model' to predict\n",
654 | "print(f\"\\n{preds3}\") # should be [196. 289.]\n",
655 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds3))}\\n\")"
656 | ],
657 | "execution_count": 45,
658 | "outputs": [
659 | {
660 | "output_type": "stream",
661 | "text": [
662 | "create pipeline 3\n",
663 | "\n",
664 | ">>>>>>>init() called.\n",
665 | "\n",
666 | "fit pipeline 3 [fit Model]\n",
667 | "\n",
668 | "*****************target_transform() called.\n",
669 | "\n",
670 | "\n",
671 | "*****************inverse_target_transform() called.\n",
672 | "\n",
673 | "\n",
674 | "*****************target_transform() called.\n",
675 | "\n",
676 | "\n",
677 | "*****************inverse_target_transform() called.\n",
678 | "\n",
679 | "\n",
680 | "*****************target_transform() called.\n",
681 | "\n",
682 | "\n",
683 | ">>>>>>>init() called.\n",
684 | "\n",
685 | "\n",
686 | ">>>>>>>fit() called.\n",
687 | "\n",
688 | "\n",
689 | "additional param ~~~~~ Himanshu\n",
690 | "\n",
691 | "\n",
692 | ">>>>>>>transform() called.\n",
693 | "\n",
694 | "predict via pipeline 3 [Model]\n",
695 | "\n",
696 | ">>>>>>>transform() called.\n",
697 | "\n",
698 | "\n",
699 | "*****************inverse_target_transform() called.\n",
700 | "\n",
701 | "\n",
702 | "[196. 289.]\n",
703 | "RMSE: 4.0194366942304644e-14\n",
704 | "\n"
705 | ],
706 | "name": "stdout"
707 | }
708 | ]
709 | },
710 | {
711 | "cell_type": "code",
712 | "metadata": {
713 | "id": "YYQ0HystcAmr",
714 | "colab_type": "code",
715 | "colab": {}
716 | },
717 | "source": [
718 | "# perfect predictions!"
719 | ],
720 | "execution_count": 0,
721 | "outputs": []
722 | },
723 | {
724 | "cell_type": "code",
725 | "metadata": {
726 | "id": "YTM-qswpcCwf",
727 | "colab_type": "code",
728 | "colab": {}
729 | },
730 | "source": [
731 | "# we can even use in-built Transformers instead of user-defined functions. Example-\n",
732 | "# model = TransformedTargetRegressor(regressor=pipe3, transformer=PowerTransformer())\n",
733 | "# or\n",
734 | "# model = TransformedTargetRegressor(regressor=pipe3, transformer=StandardScaler())\n",
735 | "# using a built-in transformer does not require us to specify the inverse_transformer() as that is taken care of internally."
736 | ],
737 | "execution_count": 0,
738 | "outputs": []
739 | },
740 | {
741 | "cell_type": "code",
742 | "metadata": {
743 | "id": "mmEs3zaKEneX",
744 | "colab_type": "code",
745 | "colab": {}
746 | },
747 | "source": [
748 | "# in case you want to have a custom transformer inside TransformedTargetRegressor, you can do that too. The only additional \n",
749 | "# function you'll have to implement would be inverse_transform(). Here's an example:"
750 | ],
751 | "execution_count": 0,
752 | "outputs": []
753 | },
754 | {
755 | "cell_type": "code",
756 | "metadata": {
757 | "id": "yBZ-S3y9_AQz",
758 | "colab_type": "code",
759 | "colab": {}
760 | },
761 | "source": [
762 | "class CustomTargetTransformer(BaseEstimator, TransformerMixin):\n",
763 | " # no need to implement __init__ in this particular case\n",
764 | " \n",
765 | " def fit(self, target):\n",
766 | " return self\n",
767 | "\n",
768 | " def transform(self, target):\n",
769 | " print('\\n%%%%%%%%%%%%%%%custom_target_transform() called.\\n')\n",
770 | " target_ = target.copy() \n",
771 | " target_ = np.sqrt(target_)\n",
772 | " return target_\n",
773 | "\n",
774 | " # need to implement this too\n",
775 | " def inverse_transform(self, target):\n",
776 | " print('\\n%%%%%%%%%%%%%%%custom_inverse_target_transform() called.\\n')\n",
777 | " target_ = target.copy() \n",
778 | " target_ = target_ ** 2\n",
779 | " return target_"
780 | ],
781 | "execution_count": 0,
782 | "outputs": []
783 | },
784 | {
785 | "cell_type": "code",
786 | "metadata": {
787 | "id": "rsCBFs6o-gBN",
788 | "colab_type": "code",
789 | "colab": {
790 | "base_uri": "https://localhost:8080/",
791 | "height": 581
792 | },
793 | "outputId": "6ea392f9-7a0a-45d1-a7d5-05a1a0ac0d41"
794 | },
795 | "source": [
796 | "# with input transformation & target transformation\n",
797 | "print(\"create pipeline 3.1\")\n",
798 | "# no change in input pipeline\n",
799 | "pipe3_1 = Pipeline(steps=[\n",
800 | " ('experimental_trans', ExperimentalTransformer_2('X2')),\n",
801 | " ('linear_model', LinearRegression())\n",
802 | "])\n",
803 | "\n",
804 | "# create a TargetTransformer \n",
805 | "# By default, the provided functions are checked at each fit to be the inverse of each other. However, it is \n",
806 | "# possible to bypass this checking by setting check_inverse to False.\n",
807 | "model = TransformedTargetRegressor(regressor=pipe3_1, \n",
808 | " transformer=CustomTargetTransformer(),\n",
809 | " check_inverse=False) # avoid repeated calls\n",
810 | "\n",
811 | "print(\"fit pipeline 3.1 [fit Model]\")\n",
812 | "model.fit(train_X, train_y) \n",
813 | "print(\"predict via pipeline 3.1 [Model]\")\n",
814 | "preds3_1 = model.predict(test_X) \n",
815 | "print(f\"\\n{preds3_1}\") # should be [196. 289.]\n",
816 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds3_1))}\\n\")"
817 | ],
818 | "execution_count": 50,
819 | "outputs": [
820 | {
821 | "output_type": "stream",
822 | "text": [
823 | "create pipeline 3.1\n",
824 | "\n",
825 | ">>>>>>>init() called.\n",
826 | "\n",
827 | "fit pipeline 3.1 [fit Model]\n",
828 | "\n",
829 | "%%%%%%%%%%%%%%%custom_target_transform() called.\n",
830 | "\n",
831 | "\n",
832 | ">>>>>>>init() called.\n",
833 | "\n",
834 | "\n",
835 | ">>>>>>>fit() called.\n",
836 | "\n",
837 | "\n",
838 | "additional param ~~~~~ Himanshu\n",
839 | "\n",
840 | "\n",
841 | ">>>>>>>transform() called.\n",
842 | "\n",
843 | "predict via pipeline 3.1 [Model]\n",
844 | "\n",
845 | ">>>>>>>transform() called.\n",
846 | "\n",
847 | "\n",
848 | "%%%%%%%%%%%%%%%custom_inverse_target_transform() called.\n",
849 | "\n",
850 | "\n",
851 | "[196. 289.]\n",
852 | "RMSE: 4.0194366942304644e-14\n",
853 | "\n"
854 | ],
855 | "name": "stdout"
856 | }
857 | ]
858 | },
859 | {
860 | "cell_type": "code",
861 | "metadata": {
862 | "id": "Ly2iew-uEhdU",
863 | "colab_type": "code",
864 | "colab": {}
865 | },
866 | "source": [
867 | "# let's now see how to get and set parameters of the model. We'll also cache the transformer to \n",
868 | "# avoid repeated computation and make it more efficient."
869 | ],
870 | "execution_count": 0,
871 | "outputs": []
872 | },
873 | {
874 | "cell_type": "code",
875 | "metadata": {
876 | "id": "I0KB3cjDC5ho",
877 | "colab_type": "code",
878 | "colab": {
879 | "base_uri": "https://localhost:8080/",
880 | "height": 490
881 | },
882 | "outputId": "e17e937f-9ff3-485a-8730-846e2851a6da"
883 | },
884 | "source": [
885 | "# get all the params of our model\n",
886 | "model.get_params()"
887 | ],
888 | "execution_count": 52,
889 | "outputs": [
890 | {
891 | "output_type": "execute_result",
892 | "data": {
893 | "text/plain": [
894 | "{'check_inverse': False,\n",
895 | " 'func': None,\n",
896 | " 'inverse_func': None,\n",
897 | " 'regressor': Pipeline(memory=None,\n",
898 | " steps=[('experimental_trans',\n",
899 | " ExperimentalTransformer_2(additional_param='Himanshu',\n",
900 | " feature_name='X2')),\n",
901 | " ('linear_model',\n",
902 | " LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
903 | " normalize=False))],\n",
904 | " verbose=False),\n",
905 | " 'regressor__experimental_trans': ExperimentalTransformer_2(additional_param='Himanshu', feature_name='X2'),\n",
906 | " 'regressor__experimental_trans__additional_param': 'Himanshu',\n",
907 | " 'regressor__experimental_trans__feature_name': 'X2',\n",
908 | " 'regressor__linear_model': LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False),\n",
909 | " 'regressor__linear_model__copy_X': True,\n",
910 | " 'regressor__linear_model__fit_intercept': True,\n",
911 | " 'regressor__linear_model__n_jobs': None,\n",
912 | " 'regressor__linear_model__normalize': False,\n",
913 | " 'regressor__memory': None,\n",
914 | " 'regressor__steps': [('experimental_trans',\n",
915 | " ExperimentalTransformer_2(additional_param='Himanshu', feature_name='X2')),\n",
916 | " ('linear_model',\n",
917 | " LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False))],\n",
918 | " 'regressor__verbose': False,\n",
919 | " 'transformer': CustomTargetTransformer()}"
920 | ]
921 | },
922 | "metadata": {
923 | "tags": []
924 | },
925 | "execution_count": 52
926 | }
927 | ]
928 | },
929 | {
930 | "cell_type": "code",
931 | "metadata": {
932 | "id": "h729iuXW26OI",
933 | "colab_type": "code",
934 | "colab": {}
935 | },
936 | "source": [
937 | "from tempfile import mkdtemp\n",
938 | "from shutil import rmtree\n",
939 | "# read about caching and side effect at: https://scikit-learn.org/stable/modules/compose.html?highlight=transformedtargetregressor#pipeline-chaining-estimators"
940 | ],
941 | "execution_count": 0,
942 | "outputs": []
943 | },
944 | {
945 | "cell_type": "code",
946 | "metadata": {
947 | "id": "ev2o5jU-Cpcb",
948 | "colab_type": "code",
949 | "colab": {
950 | "base_uri": "https://localhost:8080/",
951 | "height": 635
952 | },
953 | "outputId": "374c1b5f-6618-4ca7-cd43-72b6f83c008b"
954 | },
955 | "source": [
956 | "cachedir = mkdtemp()\n",
957 | "print(\"create pipeline 4\")\n",
958 | "pipe4 = Pipeline(steps=[\n",
959 | " # incorrect column name passed\n",
960 | " ('experimental_trans', ExperimentalTransformer_2('X1')), \n",
961 | " ('linear_model', LinearRegression())\n",
962 | "], memory=cachedir)\n",
963 | "# create a TargetTransformer\n",
964 | "model = TransformedTargetRegressor(regressor=pipe4, \n",
965 | " func=target_transform, \n",
966 | " inverse_func=inverse_target_transform, \n",
967 | " check_inverse=False) \n",
968 | "# correcting the column name using set_params()\n",
969 | "model.set_params(regressor__experimental_trans__feature_name = 'X2') \n",
970 | "\n",
971 | "print(\"fit pipeline 4 [fit Model]\")\n",
972 | "model.fit(train_X, train_y) \n",
973 | "print(\"predict via pipeline 4 [Model]\")\n",
974 | "preds4 = model.predict(test_X) \n",
975 | "print(f\"\\n{preds4}\") # should be [196. 289.]\n",
976 | "print(f\"RMSE: {np.sqrt(mean_squared_error(test_y, preds4))}\\n\")\n",
977 | "\n",
978 | "# Clear the cache directory when you don't need it anymore\n",
979 | "rmtree(cachedir)"
980 | ],
981 | "execution_count": 54,
982 | "outputs": [
983 | {
984 | "output_type": "stream",
985 | "text": [
986 | "create pipeline 4\n",
987 | "\n",
988 | ">>>>>>>init() called.\n",
989 | "\n",
990 | "fit pipeline 4 [fit Model]\n",
991 | "\n",
992 | "*****************target_transform() called.\n",
993 | "\n",
994 | "\n",
995 | ">>>>>>>init() called.\n",
996 | "\n",
997 | "\n",
998 | ">>>>>>>init() called.\n",
999 | "\n",
1000 | "\n",
1001 | ">>>>>>>fit() called.\n",
1002 | "\n",
1003 | "\n",
1004 | "additional param ~~~~~ Himanshu\n",
1005 | "\n",
1006 | "\n",
1007 | ">>>>>>>transform() called.\n",
1008 | "\n",
1009 | "predict via pipeline 4 [Model]\n",
1010 | "\n",
1011 | ">>>>>>>transform() called.\n",
1012 | "\n",
1013 | "\n",
1014 | "*****************inverse_target_transform() called.\n",
1015 | "\n",
1016 | "\n",
1017 | "[196. 289.]\n",
1018 | "RMSE: 4.0194366942304644e-14\n",
1019 | "\n"
1020 | ],
1021 | "name": "stdout"
1022 | }
1023 | ]
1024 | },
1025 | {
1026 | "cell_type": "code",
1027 | "metadata": {
1028 | "id": "_5ZCrirHIADe",
1029 | "colab_type": "code",
1030 | "colab": {}
1031 | },
1032 | "source": [
1033 | "# NEXT STEPS:\n",
1034 | "\n",
1035 | "# 1. FeatureUnion and ColumnTransformer\n",
1036 | "# Some great examples:\n",
1037 | "# https://scikit-learn.org/stable/modules/compose.html#featureunion-composite-feature-spaces \n",
1038 | "# https://scikit-learn.org/stable/modules/generated/sklearn.compose.ColumnTransformer.html#sklearn.compose.ColumnTransformer\n",
1039 | "\n",
1040 | "\n",
1041 | "# 2. Using GridSearch with Pipelines\n",
1042 | "# Example: https://scikit-learn.org/stable/auto_examples/compose/plot_feature_union.html?highlight=pipeline\n"
1043 | ],
1044 | "execution_count": 0,
1045 | "outputs": []
1046 | },
1047 | {
1048 | "cell_type": "code",
1049 | "metadata": {
1050 | "id": "M7b3qRdI3EMB",
1051 | "colab_type": "code",
1052 | "colab": {}
1053 | },
1054 | "source": [
1055 | ""
1056 | ],
1057 | "execution_count": 0,
1058 | "outputs": []
1059 | }
1060 | ]
1061 | }
--------------------------------------------------------------------------------
/PipelineFoundation/README.md:
--------------------------------------------------------------------------------
1 | #iamJustAStudent - Let's study AI/ML together : http://iamjustastudent.com
2 | # Pipelines & Custom Transformers in scikit-learn: The step-by-step guide (with Python code)
3 | Understand the basics and workings of scikit-learn pipelines from the ground up, so that you can build your own..
4 |
5 | Watch the video tutorial at: https://youtu.be/mOYJCR0IDk8
6 | or
7 | Read the complete tutorial at: https://towardsdatascience.com/pipelines-custom-transformers-in-scikit-learn-the-step-by-step-guide-with-python-code-4a7d9b068156
8 |
--------------------------------------------------------------------------------
/Predicted_R-squared/PredictedR2.csv:
--------------------------------------------------------------------------------
1 | X,Y
2 | 70,23
3 | 68,30
4 | 76,26
5 | 69,11
6 | 82,10
7 | 83,3
8 | 79,9
9 | 78,12
10 | 88,7
11 | 91,39
12 | 89,23
13 | 73,19
14 |
--------------------------------------------------------------------------------
/Predicted_R-squared/README.md:
--------------------------------------------------------------------------------
1 | #iamJustAStudent - Let's study AI/ML together : http://iamjustastudent.com
2 | # Predicted R-squared
3 | An awesome metric you haven't heard of!
4 |
5 | ## Step by Step Guide:
6 | https://iamjustastudent.com/2020/09/07/predicted-r-squared-an-awesome-metric-you-havent-heard-of/
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MachineLearning
2 | Let's study AI/ML together.
3 |
--------------------------------------------------------------------------------
/SleepyOne/README.md:
--------------------------------------------------------------------------------
1 | #iamJustAStudent - Let's study AI/ML together : http://iamjustastudent.com
2 | # SleepyOne
3 | A Fun Project (Pose Detector) With Google's Teachable Machine
4 |
5 | ## Step by Step Guide:
6 | https://medium.com/@himanshuhc/a-fun-project-pose-detector-with-googles-teachable-machine-6c7c8d650be1
7 |
--------------------------------------------------------------------------------
/SleepyOne/index.html:
--------------------------------------------------------------------------------
1 |