Di Javascript, seluruh variable, function, dan object apapun, adalah merujuk ke satu obyek utama, yaitu Show Obyek 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 // ketika suatu variable didefinisikan secara langsung // akan membuat variable tersebut otomatis menjadi property dari object window s = 'hello'; // sama juga ketika mendaftarkan sebuah property pada object window window['t'] = 'world'; function say1() { // s dan t akan diambil dari window // karena tidak didefinisikan dalam function return 'fn say1 = ' + s + ' ' + t; } function say2() { var t = 'universe'; // meskipun dalam function ini ada mendifinisikan variable t, // namun variable tersebut didefinisikan dengan keyword var // menjadikan akses ke variable tersebut hanya dalam scope function // sedangkan dalam kasus ini, secara eksplisit, kita mengambil nilai t dari object window return 'fn say2 = ' + window.s + ' ' + window.t; } // deklarasi say3 adalah dianggap sebagai variable // tanpa keyword var, maka akan otomatis menjadi property dari window say3 = function(t){ // pada fungsi ini, variable t tidak akan diambil dari object window, // karena scope function, juga memiliki properti t // bandingkan dengan say2 di atas return 'fn say3: hello ' + t; } function say4(){ // di javascript, function pun adalah sebuah properti object // dalam kasus ini, say3 adalah sebuah variable, dengan tipe ada function // sehingga dapat diakses langsung pada object window, dan dieksekusi return 'say 4: ' + window['say3']('Toni') } // variable custom1 dideklarasikan secara langsung menjadi properti dari window window.custom1 = 'rajin'; function getCustom1(){ // variable custom1 otomatis diambil dari object window // karena tidak ada variable custom1 dalam scope ini return 'sifat budi: ' + custom1 } function getCustom2(){ var custom1 = 'budi'; // karena variable custom1 dideklarasikan dalam scope function ini, // maka untuk mengakses custom1 milik window, harus ditulis secara lengkap return custom1 + ' ' + window.custom1 } // variable ini didefinisikan dengan keyword var // menjadikan variable ini hanya berjalan scope saat ini, dan bukan global // dengan demikian, variable itu tidak menjadi property dari object window // say5 akan menghasilkan undefined, karena tidak dapat mengakses variable notInWindow var notInWindow = 'variable bukan dalam window'; function say5(){ return window.notInWindow; } Demikian penjelasan Berikut implementasi script di atas. Setelah membaca artikel ini, diharapkan Anda lebih paham mengenai scope variable dalam javascript, terutama berkaitan dengan obyek This tutorial demonstrates using Visual Studio Code and the Microsoft Python extension with common data science libraries to explore a basic data science scenario. Specifically, using passenger data from the Titanic, you will learn how to set up a data science environment, import and clean data, create a machine learning model for predicting survival on the Titanic, and evaluate the accuracy of the generated model. PrerequisitesThe following installations are required for the completion of this tutorial. Make sure to install them if you haven't already.
Set up a data science environmentVisual Studio Code and the Python extension provide a great editor for data science scenarios. With native support for Jupyter notebooks combined with Anaconda, it's easy to get started. In this section, you will create a workspace for the tutorial, create an Anaconda environment with the data science modules needed for the tutorial, and create a Jupyter notebook that you'll use for creating a machine learning model.
Prepare the dataThis tutorial uses the Titanic dataset available on OpenML.org, which is obtained from Vanderbilt University's Department of Biostatistics at https://hbiostat.org/data. The Titanic data provides information about the survival of passengers on the Titanic and characteristics about the passengers such as age and ticket class. Using this data, the tutorial will establish a model for predicting whether a given passenger would have survived the sinking of the Titanic. This section shows how to load and manipulate data in your Jupyter notebook.
Train and evaluate a modelWith the dataset ready, you can now begin creating a model. For this section, you'll use the scikit-learn library (as it offers some useful helper functions) to do pre-processing of the dataset, train a classification model to determine survivability on the Titanic, and then use that model with test data to determine its accuracy.
(Optional) Use a neural networkA neural network is a model that uses weights and activation functions, modeling aspects of human neurons, to determine an outcome based on provided inputs. Unlike the machine learning algorithm you looked at previously, neural networks are a form of deep learning wherein you don't need to know an ideal algorithm for your problem set ahead of time. It can be used for many different scenarios and classification is one of them. For this section, you'll use the Keras library with TensorFlow to construct the neural network, and explore how it handles the Titanic dataset.
Next stepsNow that you're familiar with the basics of performing machine learning within Visual Studio Code, here are some other Microsoft resources and tutorials to check out. |